3 ms·
More generally, I believe this is a monad structure.
by maest 4y ago
More generally, I believe this is a monad structure.
- pdpi 4y agoPromises are not monads, for one simple reason: they're not referentially transparent. The whole point of OP's example is to double down and take advantage of that.
- epolanski 4y agoReferential transparency is a property of expressions, not type classes. Referential transparency is nowhere in the definition of a monad because a monad is obviously not an expression but a type class. It is definitely true that Promise is a data type that _could_ admit a monad instance. It has: - a data type M a which is Promise a - a function pure with the signature a => M a, which is x => Promise.resolve(x) - a bind function with the signature M a => a => M b => M b which is essentialy `then` But a monad requires three properties to hold true: Right identity, Left identity and associativity. Right identity holds for every function `f: a => M b`, but left identity and associativity do not hold.
- brewmarche 4y agoMaybe comonads fit better