hemanth/functional-programming-jargon

Applicative Functor

Closed this issue · 4 comments

I think the the output for the example described is not accurate.

`
// Implementation
Array.prototype.ap = function(xs){
return this.reduce((acc, f) => acc.concat(xs.map(f)), []);
};

// Arrays that you want to combine
const arg1 = [1, 2];
const arg2 = [3, 4];

// combining function - must be curried for this to work
const add = (x) => (y) => x + y;

const partiallyAppliedAdds = [add].ap(arg1); // [(y) => 1 + y, (y) => 2 + y]
`

The following would result in
partiallyAppliedAdds.ap(arg2); // [4, 5, 5, 6]

Thanks for letting us know :)

You're welcome to submit a PR if you like

@jethrolarson there you go !

Close this?

Yes