1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _map =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_map");
|
8 |
|
9 | var curryN =
|
10 | /*#__PURE__*/
|
11 | require("./curryN");
|
12 |
|
13 | var max =
|
14 | /*#__PURE__*/
|
15 | require("./max");
|
16 |
|
17 | var pluck =
|
18 | /*#__PURE__*/
|
19 | require("./pluck");
|
20 |
|
21 | var reduce =
|
22 | /*#__PURE__*/
|
23 | require("./reduce");
|
24 | /**
|
25 | * Accepts a converging function and a list of branching functions and returns
|
26 | * a new function. The arity of the new function is the same as the arity of
|
27 | * the longest branching function. When invoked, this new function is applied
|
28 | * to some arguments, and each branching function is applied to those same
|
29 | * arguments. The results of each branching function are passed as arguments
|
30 | * to the converging function to produce the return value.
|
31 | *
|
32 | * @func
|
33 | * @memberOf R
|
34 | * @since v0.4.2
|
35 | * @category Function
|
36 | * @sig ((x1, x2, ...) -> z) -> [((a, b, ...) -> x1), ((a, b, ...) -> x2), ...] -> (a -> b -> ... -> z)
|
37 | * @param {Function} after A function. `after` will be invoked with the return values of
|
38 | * `fn1` and `fn2` as its arguments.
|
39 | * @param {Array} functions A list of functions.
|
40 | * @return {Function} A new function.
|
41 | * @see R.useWith
|
42 | * @example
|
43 | *
|
44 | * const average = R.converge(R.divide, [R.sum, R.length])
|
45 | * average([1, 2, 3, 4, 5, 6, 7]) //=> 4
|
46 | *
|
47 | * const strangeConcat = R.converge(R.concat, [R.toUpper, R.toLower])
|
48 | * strangeConcat("Yodel") //=> "YODELyodel"
|
49 | *
|
50 | * @symb R.converge(f, [g, h])(a, b) = f(g(a, b), h(a, b))
|
51 | */
|
52 |
|
53 |
|
54 | var converge =
|
55 | /*#__PURE__*/
|
56 | _curry2(function converge(after, fns) {
|
57 | return curryN(reduce(max, 0, pluck('length', fns)), function () {
|
58 | var args = arguments;
|
59 | var context = this;
|
60 | return after.apply(context, _map(function (fn) {
|
61 | return fn.apply(context, args);
|
62 | }, fns));
|
63 | });
|
64 | });
|
65 |
|
66 | module.exports = converge; |
\ | No newline at end of file |