Last active
February 23, 2016 13:52
-
-
Save ulfryk/b026f807dae799dbc328 to your computer and use it in GitHub Desktop.
JS Promisees vs. Monads
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
// Axioms | |
unit(value).bind(f) <=> f(value); | |
monad.bind(unit) == monad; | |
monad.bind(f).bind(g) == monad.bind(value => f(value).bind(g)) | |
// Promise | |
Promise.resolve(value).then(f) <=> f(value) | |
promise.then(Promise.resolve) == promise | |
promise.then(f).then(g) != promise.then(value => f(value).then(g)) // f for promises can return value or promise - fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment