source: node_modules/ramda-adjunct/es/reduceIndexed.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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