Travis build: 1584

This commit is contained in:
30secondsofcode
2018-02-07 10:24:32 +00:00
parent da80f53f2b
commit 2b2e88738c
3 changed files with 37 additions and 4 deletions

View File

@ -231,6 +231,7 @@ average(1, 2, 3);
* [`chainAsync`](#chainasync)
* [`compose`](#compose)
* [`composeRight`](#composeright)
* [`converge`](#converge)
* [`curry`](#curry)
* [`debounce`](#debounce)
* [`defer`](#defer)
@ -3766,6 +3767,33 @@ addAndSquare(1, 2); // 9
<br>[⬆ Back to top](#table-of-contents)
### converge
Accepts a converging function and a list of branching functions and returns a function that applies each branching function to the arguments and the results of the branching functions are passed as arguments to the converging function.
Use `Array.map()` and `Function.apply()` to apply each function to the given arguments.
Use the spread operator (`...`) to call `coverger` with the results of all other functions.
```js
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
```
<details>
<summary>Examples</summary>
```js
const average = converge((a, b) => a / b, [
arr => arr.reduce((a, v) => a + v, 0),
arr => arr.length
]);
average([1, 2, 3, 4, 5, 6, 7]); // 4
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### curry
Curries a function.

File diff suppressed because one or more lines are too long

View File

@ -6,14 +6,13 @@ Use `Array.map()` and `Function.apply()` to apply each function to the given arg
Use the spread operator (`...`) to call `coverger` with the results of all other functions.
```js
const converge = (converger, fns) => (...args) =>
converger(...fns.map(fn => fn.apply(null, args)));
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
```
```js
const average = converge((a, b) => a / b, [
arr => arr.reduce((a, v) => a + v, 0),
arr => arr.length,
arr => arr.length
]);
average([1, 2, 3, 4, 5, 6, 7]); // 4
```