source: node_modules/ramda-adjunct/lib/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.3 KB
RevLine 
[d24f17c]1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5var _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 */
32var reduceIndexed = (0, _ramda.addIndex)(_ramda.reduce);
33var _default = reduceIndexed;
34exports["default"] = _default;
Note: See TracBrowser for help on using the repository browser.