-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Question about Option's Foldable / reduce
implementation
#495
Comments
Type inference goes from left to right, so this signature helps typing the reducer some('foo').reduce(0, (b, a) => ) // b is inferred as number, a as string |
I tried this with Typescript 2.9 function test<A>( x: (a) => A, y: A ): A {
return y
}
test( _ => 'a' ,1 ) I get the error
Also with currying function test<A>( x: (a) => A ): (y:A) => A {
return (y: A) => y
}
test( _ => 'a')( 1 ) I get the error
|
@babakness these errors are legit. |
@sledorze Well, my original comment:
I wanted to know why not comply with the fantasy-land Maybe I'm misunderstanding something? Thanks |
@babakness the actual order favors developper experience, meaning it is easier to fill in the reducer initial value and then fill in the reduce function as all type parameters have been discovered by the compiler. |
Hi @sledorze Wouldn't the developer experience be addressed by have two methods as such
Line 250 in 3284938
Line 253 in 3284938
Or perhaps other names. Then implementing the methods named per Fantasyland specs for the sake of inter-operability between libraries? Again, still having other methods for sake of developer experience. Note: I believe the current I also very curious about the mentioned developer experience! I guess I'm used to |
Related #204 |
Closing this as @sledorze's answer explains the rationale of the current choice |
Hey, I want to know how to use foldMap of Option. Can i get any simple examples here? |
@ElamuruganGR Not tested but eyeballing it this looks right. export declare const foldMap: <M>(M: Monoid<M>) => <A>(f: (a: A) => M) => (fa: Option<A>) => M import * as O from 'fp-ts/Option'
import * as Str from 'fp-ts/string'
import { pipe } from 'fp-ts/function'
declare const x: Option<string>
pipe(x, O.foldMap(Str.Monoid)(x => x + '!')) |
Thanks @samhh Its working. |
Hello, great library! Just a brief question:
I've noticed that
Option
'sfoldable
fp-ts/src/Option.ts
Line 259 in 3284938
is in the opposite order of FantasyLand Foldable
https://github.com/fantasyland/fantasy-land#foldable
u.reduce(f, x)
I'm might be totally misunderstanding that.
The text was updated successfully, but these errors were encountered: