1 | var _curry3 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry3");
|
4 |
|
5 | var _reduce =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_reduce");
|
8 | /**
|
9 | * Returns a single item by iterating through the list, successively calling
|
10 | * the iterator function and passing it an accumulator value and the current
|
11 | * value from the array, and then passing the result to the next call.
|
12 | *
|
13 | * The iterator function receives two values: *(acc, value)*. It may use
|
14 | * [`R.reduced`](#reduced) to shortcut the iteration.
|
15 | *
|
16 | * The arguments' order of [`reduceRight`](#reduceRight)'s iterator function
|
17 | * is *(value, acc)*.
|
18 | *
|
19 | * Note: `R.reduce` does not skip deleted or unassigned indices (sparse
|
20 | * arrays), unlike the native `Array.prototype.reduce` method. For more details
|
21 | * on this behavior, see:
|
22 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce#Description
|
23 | *
|
24 | * Dispatches to the `reduce` method of the third argument, if present. When
|
25 | * doing so, it is up to the user to handle the [`R.reduced`](#reduced)
|
26 | * shortcuting, as this is not implemented by `reduce`.
|
27 | *
|
28 | * @func
|
29 | * @memberOf R
|
30 | * @since v0.1.0
|
31 | * @category List
|
32 | * @sig ((a, b) -> a) -> a -> [b] -> a
|
33 | * @param {Function} fn The iterator function. Receives two values, the accumulator and the
|
34 | * current element from the array.
|
35 | * @param {*} acc The accumulator value.
|
36 | * @param {Array} list The list to iterate over.
|
37 | * @return {*} The final, accumulated value.
|
38 | * @see R.reduced, R.addIndex, R.reduceRight
|
39 | * @example
|
40 | *
|
41 | * R.reduce(R.subtract, 0, [1, 2, 3, 4]) // => ((((0 - 1) - 2) - 3) - 4) = -10
|
42 | * // - -10
|
43 | * // / \ / \
|
44 | * // - 4 -6 4
|
45 | * // / \ / \
|
46 | * // - 3 ==> -3 3
|
47 | * // / \ / \
|
48 | * // - 2 -1 2
|
49 | * // / \ / \
|
50 | * // 0 1 0 1
|
51 | *
|
52 | * @symb R.reduce(f, a, [b, c, d]) = f(f(f(a, b), c), d)
|
53 | */
|
54 |
|
55 |
|
56 | var reduce =
|
57 | /*#__PURE__*/
|
58 | _curry3(_reduce);
|
59 |
|
60 | module.exports = reduce; |
\ | No newline at end of file |