Last active
November 3, 2018 20:18
-
-
Save wuct/6964a9b426c625b2bb774ef4cd9c7f12 to your computer and use it in GitHub Desktop.
Let JavaScript Promise be a functor
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
Promise.prototype.fmap = Promise.prototype.then | |
Promise.resolve('yolo') | |
.fmap(str => str + ' swag!') | |
.then(console.log) // "yolo swag!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
promise.then(x => g(f(x))) is NOT equivalent to promise.then(f).then(g)
see
https://stackoverflow.com/questions/45712106/why-are-promises-monads