3 ms·
If we wanted to be picky, promises technically aren't monads because .then() does too much with auto unwrapping nested promises. https://stackoverflow.com/a/50
by dvlsg 8y ago
If we wanted to be picky, promises technically aren't monads because .then() does too much with auto unwrapping nested promises.
https://stackoverflow.com/a/50173415 https://stackoverflow.com/a/50173415 has some good examples.
It's close, though. Really close. And don't get me wrong - I still love promises and async / await. They're much better than what we had before.
- tathougies 8y agoThat post is misguided for so many reasons. In order to say something 'forms a monad', you need to define over what operations. That poster assumes Promise forms a monad using regular javascript function composition as the function composition operator. This is stated without justification, and there are other notions of javascript function composition which would preserve the functor composition law. More clearly, Promise indeed forms a functor, if the domain is the set of Javascript functions which do not return 'Promise<X>'.