Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add map2, map3, map4 to Apply? #322

Closed
gcanti opened this issue Feb 16, 2018 · 3 comments
Closed

Add map2, map3, map4 to Apply? #322

gcanti opened this issue Feb 16, 2018 · 3 comments

Comments

@gcanti
Copy link
Owner

gcanti commented Feb 16, 2018

What I do now

import { Option } from 'fp-ts/lib/Option'

const mapOption2 = <A, B, R>(fa: Option<A>, fb: Option<B>, f: (a: A, b: B) => R): Option<R> => {
  return fb.ap(fa.map(a => (b: B) => f(a, b)))
}

const r = mapOption2(some(1), some(2), (a, b) => a + b)

versus

import { option } from 'fp-ts/lib/Option'
import { map2 } from 'fp-ts/lib/Apply'

const r = map2(option)(some(1), some(2), (a, b) => a + b)
@raveclassic
Copy link
Collaborator

I'm using specialized version of sequence (specialized to array as traversable):

export function combine<A>(a: Option<A>): Option<[A]>;
export function combine<A, B>(a: Option<A>, b: Option<B>): Option<[A, B]>;
export function combine<A, B, C>(a: Option<A>, b: Option<B>, c: Option<C>): Option<[A, B, C]>;
export function combine<A, B, C, D>(a: Option<A>, b: Option<B>, c: Option<C>, d: Option<D>): Option<[A, B, C, D]>;
export function combine<T>(...list: Option<T>[]): Option<T[]> {
	return sequence(option, array)(list);
}

const foo = combine(some(1), some(2)).map(([a, b]) => a + b);

Applicative (option) can be generalized though.

@volrk
Copy link

volrk commented Apr 13, 2019

Hey, I'm new in the open-source world and I'm trying to find a projet where I can help. Is this feature still needed ?

@giogonzo
Copy link
Collaborator

Hi @volrk , and sorry for the late reply. As of now we have sequenceT (and the S variant) which pretty much cover the same use case, more generically. I'm closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants