Closed iLikeKoffee closed 3 years ago
@iLikeKoffee I really like this idea, just have to think about typesafety.
declare const applicative: Maybe<(a: number) => (b: number) => number>;
applicative
.flatMap(fn => maybeA.map(a => fn(a))) // ts knows that `fn` is function accepting number, returning function
.flatMap(fn => maybeB.map(b => fn(b))) // ts knows that `fn` here is a funciton accepting number, returning number
.forEach(v => console.log(v)) // ts knows that `v` is a number
But above example is ugly :(
We should investigate if there is a nice way to express apTo
in TS and if not , maybe add it with some tradoffs (runtime checks? ).
But anyway - let's move this discussion to #206
(and yes, it's a pity that JS doesn't have infix operators 🙃 )
Closing, as duplicate of #206
Hello. First of all - thank you for awesome library. This is really great. I've got a little feature request.
AFAIK, common usage of
Applicatives
in haskell - applying function with N arguments to values. Just, something like this(example from here):If i want to achieve the same behaviour with Monet, i should do something like this:
My proposal is to create an alias for
Applicative.ap
with swapped arguments(this and value) order, Quick & dirty proof of concept:JS cannot apply functions in haskell-like style (I mean
firstArg f secondArg
), so this alias seems suitable to me. If there is no objections against this proposal i would gladly implement it and provide a PR.P.S. PoC in CodeSandbox