Created
May 17, 2016 14:25
-
-
Save andredublin/0a970758a38ff65bcd1e5bd37a93a911 to your computer and use it in GitHub Desktop.
js applicative
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
var add = (x, y) => x + y | |
add(Identity.of(2), Identity.of(3)); // "[object Object][object Object]" | |
var map = curry(function(f, ary) { | |
return ary.map(f) | |
}); | |
var identityOf2 = map(add, Identity.of(2)); | |
// Identity(add(2)) | |
Identity.prototype.ap = function(other_container) { | |
return other_container.map(this.__value); | |
} | |
Identity.of(add(2)).ap(Identity.of(3)); | |
// Identity(5) | |
// all together now | |
Identity.of(2).map(add).ap(Identity.of(3)); | |
// Identity(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment