|
|
|
|
|
by KPGv2
138 days ago
|
|
> All asynchronous interfaces form a monad whether you decide to follow the Haskell monad type class or decide to do something els JS's then is categorically not a monad because it doesn't follow the monad laws. fn1 : a -> Promise<b> fn2 : b -> c fn3 : b -> Promise<c> With JavaScript, composing fn1 and fn2 with then gives you a -> Promise<c>. So then is isomorphic to map. With JavaScript, composing fn1 and fn3 with then gives you a -> Promise<c>. So then is isomorphic to flatmap. Therefore, with JavaScript, map is isomorphic to flatmap. Which obviously violates monad laws. There's a rather famous Github issue where someone points this out in the issue tracker for `then` development, and one of the devs in charge of then...leaves responses for posterity. |
|