3 ms·
Obviously, not all railways are like Promises (they don't need to be async) but Promises are kind of railways, as the parent commenter said. Not sure what you
by vimslayer 8y ago
Obviously, not all railways are like Promises (they don't need to be async) but Promises are kind of railways, as the parent commenter said.
Not sure what you mean by "recursively build up and tear down" but this JS snippet sure looks a lot like the F# one in the slides
const updateCustomerWithErrorHandling = (...args) =>
receiveRequest(...args)
.then(validateRequest)
.then(canonicalizeEmail)
.then(updateDbFromRequest)
.then(sendEmail)
.then(handleSuccess, handleError)
Here, each of the functions can return a result (async or not) or reject with Promise.reject or by throwing. If any of the functions rejects, the rest of the functions in this "happy path" are not called.
- ghthor 8y agoPromises don't have to be around either.
- joshribakoff 8y agoEach .then replaces the promise before, instead of wrapping the source promise around it. At each step you have a resolved value, with a monad you'd have to .flatMap because mappining a monad to a monad nests it, which you have to later flatMap to extract the boxed values. Compare rxjs streams which are monads to promises which are functors. monads are functors but not vice versa.