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.
|
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()`.
|
Use `Array.prototype.reduce()` and the spread operator (`...`) to perform 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`.
|
The functions can return a combination of normal values, `Promise`s or be `async`, returning through `await`.
|
||||||
All functions must be unary.
|
All functions must accept a single argument.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
|
const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
|
||||||
|
|||||||
Reference in New Issue
Block a user