5 ms·
Promise as a poorman's monad to do railroad-style programming works surprisingly well, even for non-async functions. I often do, Promise.resolve()
by ww520 7y ago
Promise as a poorman's monad to do railroad-style programming works surprisingly well, even for non-async functions. I often do,
Promise.resolve()
.then(dothis)
.then(dothat)
.then(doit)
.then(domore)
.catch(e => log.error(e))
It mixes well with regular try/throw.
- WaxProlix 7y agoI did this a ton when building some mixed-sync/async stuff in TypeScript, and tend to use it (or something like it, depending on the language) for any situation that looks sufficiently similar. What are the downsides to this? Why isn't it more common? (or maybe it is, and I'm just not reading the right code to see it)
- ww520 7y agoNot many people get the hang of Promise style programming. People prefer async/await.