Created
September 23, 2016 06:43
-
-
Save mocheng/9726d24242d39a8e7b8124e66c5294bb to your computer and use it in GitHub Desktop.
Applicative in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.ap = function(wrappedVals) { | |
var results = []; | |
this.map( (f)=> { | |
const mr = wrappedVals.map(f); | |
results = results.concat(mr); | |
}); | |
return results; | |
} | |
const r = [x=>x*2, y=>y+3].ap([1,2,3]); | |
console.log(r); | |
//output: [ 2, 4, 6, 4, 5, 6 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment