1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | /**
|
---|
7 | * {@link http://ramdajs.com/docs/#reduce|R.reduce} function that more closely resembles Array.prototype.reduce.
|
---|
8 | * It takes two new parameters to its callback function: the current index, and the entire list.
|
---|
9 | *
|
---|
10 | * `reduceIndexed` implementation is simple : `
|
---|
11 | * const reduceIndexed = R.addIndex(R.reduce);
|
---|
12 | * `
|
---|
13 | * @func reduceIndexed
|
---|
14 | * @memberOf RA
|
---|
15 | * @since {@link https://char0n.github.io/ramda-adjunct/2.5.0|v2.5.0}
|
---|
16 | * @category List
|
---|
17 | * @typedef Idx = Number
|
---|
18 | * @sig ((a, b, Idx, [b]) => a) -> a -> [b] -> a
|
---|
19 | * @param {Function} fn The iterator function. Receives four values,
|
---|
20 | * the accumulator, the current element from the array, index and the entire list
|
---|
21 | * @param {*} acc The accumulator value
|
---|
22 | * @param {Array} list The list to iterate over
|
---|
23 | * @return {*} The final, accumulated value
|
---|
24 | * @see {@link http://ramdajs.com/docs/#addIndex|R.addIndex}, {@link http://ramdajs.com/docs/#reduce|R.reduce}
|
---|
25 | * @example
|
---|
26 | *
|
---|
27 | * const initialList = ['f', 'o', 'o', 'b', 'a', 'r'];
|
---|
28 | *
|
---|
29 | * reduceIndexed((acc, val, idx, list) => acc + '-' + val + idx, '', initialList);
|
---|
30 | * //=> "-f0-o1-o2-b3-a4-r5"
|
---|
31 | */
|
---|
32 | var reduceIndexed = (0, _ramda.addIndex)(_ramda.reduce);
|
---|
33 | var _default = reduceIndexed;
|
---|
34 | exports["default"] = _default; |
---|