Update pipeAsyncFunctions.md

This commit is contained in:
Angelos Chalaris
2020-04-29 09:07:45 +03:00
committed by GitHub
parent 46017fde6f
commit 306250eaf8

View File

@ -5,9 +5,9 @@ tags: function,promise,intermediate
Performs left-to-right function composition for asynchronous functions.
Use `Array.prototype.reduce()` with the spread operator (`...`) to perform left-to-right function composition using `Promise.then()`.
The functions can return a combination of: simple values, `Promise`'s, or they can be defined as `async` ones returning through `await`.
All functions must be unary.
Use `Array.prototype.reduce()` and the spread operator (`...`) to perform function composition using `Promise.then()`.
The functions can return a combination of normal values, `Promise`s or be `async`, returning through `await`.
All functions must accept a single argument.
```js
const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));