source: node_modules/ramda-adjunct/src/mapIndexed.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.0 KB
Line 
1import { addIndex, map } from 'ramda';
2
3/**
4 * {@link http://ramdajs.com/docs/#map|R.map} function that more closely resembles Array.prototype.map.
5 * It takes two new parameters to its callback function: the current index, and the entire list.
6 *
7 * `mapIndexed` implementation is simple : `
8 * const mapIndexed = R.addIndex(R.map);
9 * `
10 * @func mapIndexed
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 Functor f => ((a, Idx, f a) => b) => f a -> f b
16 * @param {Function} fn The function to be called on every element of the input `list`
17 * @param {Array} list The list to be iterated over
18 * @return {Array} The new list
19 * @see {@link http://ramdajs.com/docs/#addIndex|R.addIndex}, {@link http://ramdajs.com/docs/#map|R.map}
20 * @example
21 *
22 * RA.mapIndexed((val, idx, list) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
23 * //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
24 */
25const mapIndexed = addIndex(map);
26
27export default mapIndexed;
Note: See TracBrowser for help on using the repository browser.