-
Notifications
You must be signed in to change notification settings - Fork 21
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 Future.liftXXX #12
Comments
note that GHC haskell also talks about lifted and unlifted types. I get the feeling the use of the 'lift' term in FP is quite loose. I may open a stackoverflow question on the subjet. |
I finally took the time to ask the question on stackoverflow. Also note, as I wrote there, that prelude.ts currently differentiates between 'lifting' (as in lifting a function returning a Promise to a function returning a Future) versus 'applicative lifting' (as in what @qm3ster -and probably most people- means by lifting). This may be bogus, looking forward to some feedback on stackoverflow. |
…tionX.liftNullable to Option.liftNullable, FunctionX.liftEither to Either.lift. Thanks @qm3ster for the tip for the implementation. Currently the functions support only up to 5 parameters, when typescript 3.1 comes out we can support any number of parameters (the feature came with TS3.0 but we want to support the two latest versions).
…ports only up to 5 parameters.
I have now committed a version using the The implementations currently use overloading and support up to 5 parameters but when TS3.1 is released I'll change them to use the new TS3 feature enabling us to support any number of parameters. |
Yeah, my usage was definitely wrong. |
I went through your link quickly, it seems to cover the |
I don't know, it's still possible to make a real lift for arbitrary uncurried function. const lift = fn => (...args) => Future.collect(args).map(arr => fn.apply(undefined, arr)) |
So you're saying liftAn for functions taking any numbers of parameters of any types. But can the type be expressed in TS? Note that prelude has liftAp: const lifted = Option.liftAp((x:{a:number,b:number,c:number}) => x.a+x.b+x.c);
lifted({a:Option.of(5), b:Option.of(6), c:Option.of(3)});
=> Option.of(14) |
Not sure if you really meant liftAn though, i'm not familiar with the collect function. |
We can type is with overloads for different lengths, with the baseline case being the too losely typed const lift = <A extends any[], R>(fn: (...args: A) => R) => (
...args: Future<A[number]>[]
) => Future.collect(args).map(arr => fn.apply(undefined, arr) as R) until Mapped Tuples are available. |
I see... With mapped tuples (currently just a proposal) we could get a typed version of As it is now, we could probably also have a version which would support up to n parameters through overloads (for a finite n). I'm not interested in the loosely typed option. I'm ok to have a finite But I'm less interested to keep it like that for a longer time (as would be with this lift, liftAp replacement). You use the feature, reach the limit in the number of parameters, then get frustrated (though in theory the user could add the extra overload typedef himself I guess). From this point of view, |
I have to say, It is really fascinating the speed at which the TS typesystem is improving. Thanks for opening me a window into some of these recent & ongoing developments! |
Its merit is that it's "Just Javascript", but neither Typescript nor flow actually let me express myself. |
yes... it has limitations. I did some things in ghcjs/reflex, unfortunately I wouldn't advise it. I would probably pick purescript, but for the foreseeable future I'll have to use something like typescript at work, I hope to make it as nice as possible with prelude.ts. Just this weekend I was playing with type-level programming (one commit, branch) in typescript, would actually be useful for prelude.ts, but I had to give up as it's advised against and would hurt build time badly. In the end, typescript not perfect, but still worth pursuing and getting better. Anyway, I'll close this bug now, I'm happy with the API as it is in master! |
We want a Future.liftXXX-like function as described there and in the rest of the conversation, and suggested by @qm3ster:
#8 (comment)
the only real hurdle left is the name for the function.
The text was updated successfully, but these errors were encountered: