source: node_modules/ramda-adjunct/src/filterIndexed.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, filter } from 'ramda';
2
3/**
4 * {@link http://ramdajs.com/docs/#filter|R.filter} function that more closely resembles `Array.prototype.filter`.
5 * It takes two new parameters to its callback function: the current index, and the entire list.
6 *
7 * `filterIndexed` implementation is simple: `
8 * const filterIndexed = R.addIndex(R.filter);
9 * `
10 *
11 * @func filterIndexed
12 * @memberOf RA
13 * @since {@link https://char0n.github.io/ramda-adjunct/2.31.0|v2.31.0}
14 * @category List
15 * @typedef Idx = Number
16 * @sig Filterable f => ((a, Idx, f a) -> Boolean) -> f a -> f a
17 * @param {Function} pred The predicate function
18 * @param {Array} list The collection to filter
19 * @return {Array} Filterable
20 * @see {@link http://ramdajs.com/docs/#addIndex|R.addIndex}, {@link http://ramdajs.com/docs/#filter|R.filter}
21 * @example
22 *
23 * const isValueGtIndex = (val, idx) => val > idx;
24 * RA.filterIndexed(isValueGtIndex, [5, 4, 3, 2, 1, 0]); //=> [5, 4, 3]
25 */
26const filterIndexed = addIndex(filter);
27
28export default filterIndexed;
Note: See TracBrowser for help on using the repository browser.