source: node_modules/ramda-adjunct/src/pickIndexes.js@ 65b6638

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

Initial commit

  • Property mode set to 100644
File size: 965 bytes
Line 
1import { filter, addIndex, curry, includes } from 'ramda';
2
3// helpers
4const filterIndexed = addIndex(filter);
5const containsIndex = curry((indexes, val, index) => includes(index, indexes));
6
7/**
8 * Picks values from list by indexes.
9 *
10 * Note: pickIndexes will skip non existing indexes. If you want to include them
11 * use ramda's `props` function.
12 *
13 * @func pickIndexes
14 * @memberOf RA
15 * @since {@link https://char0n.github.io/ramda-adjunct/1.1.0|v1.1.0}
16 * @category List
17 * @sig [Number] -> [a] -> [a]
18 * @param {Array} indexes The indexes to pick
19 * @param {Array} list The list to pick values from
20 * @return {Array} New array containing only values at `indexes`
21 * @see {@link http://ramdajs.com/docs/#pick|R.pick}, {@link RA.omitIndexes|omitIndexes}
22 * @example
23 *
24 * RA.pickIndexes([0, 2], ['a', 'b', 'c']); //=> ['a', 'c']
25 */
26const pickIndexes = curry((indexes, list) =>
27 filterIndexed(containsIndex(indexes), list)
28);
29
30export default pickIndexes;
Note: See TracBrowser for help on using the repository browser.