3 ms·
The convenience of `promise.then` behaving both like monad's `chain` and `map` comes at a cost of ambiguity in some cases.
by voreny 4y ago
The convenience of `promise.then` behaving both like monad's `chain` and `map` comes at a cost of ambiguity in some cases.
- jschrf 4y agoStop using .then wherever possible. (and also avoid using .map for side effects! Prefer foreach for!)
- voreny 4y agoHow would using async/await help here? It has the same issue of implicitly awaiting the Promise that is returned from an `async` function. In fact, your comment inspired me to go into more depth regarding the problems of `async`/`await` syntax: https://news.ycombinator.com/item?id=33322184 https://news.ycombinator.com/item?id=33322184 As for `.map`, I was referring the monadic `.map`, not `Array.prototype.map`. Either way, I agree `.map` is not for side-effects. The article says nothing about side-effects, so I'm not sure where this remark is coming from.