Travis build: 1463

This commit is contained in:
30secondsofcode
2018-01-28 12:31:14 +00:00
parent 466972f1ef
commit 00c14d69d5
2 changed files with 44 additions and 1 deletions

View File

@ -82,6 +82,7 @@ average(1, 2, 3);
* [`collectInto`](#collectinto)
* [`flip`](#flip)
* [`over`](#over)
* [`pipeAsyncFunctions`](#pipeasyncfunctions)
* [`pipeFunctions`](#pipefunctions)
* [`promisify`](#promisify)
* [`spreadOver`](#spreadover)
@ -554,6 +555,38 @@ minMax(1, 2, 3, 4, 5); // [1,5]
<br>[⬆ Back to top](#table-of-contents)
### pipeAsyncFunctions
Performs left-to-right function composition for asynchronous functions.
Use `Array.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.
```js
const pipeAsyncFunctions = (...fns) => arg => fns.reduce((p, f) => p.then(f), Promise.resolve(arg));
```
<details>
<summary>Examples</summary>
```js
const sum = pipeAsyncFunctions(
x => x + 1,
x => new Promise(resolve => setTimeout(() => resolve(x + 2), 1000)),
x => x + 3,
async x => (await x) + 4
);
(async () => {
console.log(await sum(5)); // 15 (after one second)
})();
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### pipeFunctions
Performs left-to-right function composition.

File diff suppressed because one or more lines are too long