Travis build: 1584
This commit is contained in:
28
README.md
28
README.md
@ -231,6 +231,7 @@ average(1, 2, 3);
|
|||||||
* [`chainAsync`](#chainasync)
|
* [`chainAsync`](#chainasync)
|
||||||
* [`compose`](#compose)
|
* [`compose`](#compose)
|
||||||
* [`composeRight`](#composeright)
|
* [`composeRight`](#composeright)
|
||||||
|
* [`converge`](#converge)
|
||||||
* [`curry`](#curry)
|
* [`curry`](#curry)
|
||||||
* [`debounce`](#debounce)
|
* [`debounce`](#debounce)
|
||||||
* [`defer`](#defer)
|
* [`defer`](#defer)
|
||||||
@ -3766,6 +3767,33 @@ addAndSquare(1, 2); // 9
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<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
|
### curry
|
||||||
|
|
||||||
Curries a function.
|
Curries a function.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -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.
|
Use the spread operator (`...`) to call `coverger` with the results of all other functions.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const converge = (converger, fns) => (...args) =>
|
const converge = (converger, fns) => (...args) => converger(...fns.map(fn => fn.apply(null, args)));
|
||||||
converger(...fns.map(fn => fn.apply(null, args)));
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const average = converge((a, b) => a / b, [
|
const average = converge((a, b) => a / b, [
|
||||||
arr => arr.reduce((a, v) => a + v, 0),
|
arr => arr.reduce((a, v) => a + v, 0),
|
||||||
arr => arr.length,
|
arr => arr.length
|
||||||
]);
|
]);
|
||||||
average([1, 2, 3, 4, 5, 6, 7]); // 4
|
average([1, 2, 3, 4, 5, 6, 7]); // 4
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user