hemanth / functional-programming-jargon

Jargon from the functional programming world in simple terms!
http://git.io/fp-jargons
MIT License
18.59k stars 1.02k forks source link

Applicative Functor #103

Closed theTechie closed 7 years ago

theTechie commented 8 years ago

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]

jethrolarson commented 8 years ago

Thanks for letting us know :)

You're welcome to submit a PR if you like

theTechie commented 8 years ago

@jethrolarson there you go !

jethrolarson commented 7 years ago

Close this?

theTechie commented 7 years ago

Yes