2 ms·
Yeah, you're right that in some manners JS's promises do extend the semantics of a monad (notably in its impl. of return) but it is a monad though: function bi
by jsjolen 7y ago
Yeah, you're right that in some manners JS's promises do extend the semantics of a monad (notably in its impl. of return) but it is a monad though:
function bindPromise(p, f) {
return p.then(f);
}
function returnPromise(a) {
return new Promise.resolve(a);
}
Proof of the laws left as an exercise to the reader :).
But yes, you are correct that promises do quite a bit more than only being a monad, for example because of how they treat errors.
EDIT: I concede, I am wrong! https://buzzdecafe.github.io/2018/04/10/no-promises-are-not-monads https://buzzdecafe.github.io/2018/04/10/no-promises-are-not-...