Update pipeAsyncFunctions.md
This commit is contained in:
@ -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));
|
||||
|
||||
Reference in New Issue
Block a user