1 | "use strict";
|
---|
2 |
|
---|
3 | exports.__esModule = true;
|
---|
4 | exports["default"] = void 0;
|
---|
5 | var _ramda = require("ramda");
|
---|
6 | // helpers
|
---|
7 | var filterIndexed = (0, _ramda.addIndex)(_ramda.filter);
|
---|
8 | var containsIndex = (0, _ramda.curry)(function (indexes, val, index) {
|
---|
9 | return (0, _ramda.includes)(index, indexes);
|
---|
10 | });
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Picks values from list by indexes.
|
---|
14 | *
|
---|
15 | * Note: pickIndexes will skip non existing indexes. If you want to include them
|
---|
16 | * use ramda's `props` function.
|
---|
17 | *
|
---|
18 | * @func pickIndexes
|
---|
19 | * @memberOf RA
|
---|
20 | * @since {@link https://char0n.github.io/ramda-adjunct/1.1.0|v1.1.0}
|
---|
21 | * @category List
|
---|
22 | * @sig [Number] -> [a] -> [a]
|
---|
23 | * @param {Array} indexes The indexes to pick
|
---|
24 | * @param {Array} list The list to pick values from
|
---|
25 | * @return {Array} New array containing only values at `indexes`
|
---|
26 | * @see {@link http://ramdajs.com/docs/#pick|R.pick}, {@link RA.omitIndexes|omitIndexes}
|
---|
27 | * @example
|
---|
28 | *
|
---|
29 | * RA.pickIndexes([0, 2], ['a', 'b', 'c']); //=> ['a', 'c']
|
---|
30 | */
|
---|
31 | var pickIndexes = (0, _ramda.curry)(function (indexes, list) {
|
---|
32 | return filterIndexed(containsIndex(indexes), list);
|
---|
33 | });
|
---|
34 | var _default = pickIndexes;
|
---|
35 | exports["default"] = _default; |
---|