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:
965 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import { filter, addIndex, curry, includes } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | // helpers
|
---|
| 4 | const filterIndexed = addIndex(filter);
|
---|
| 5 | const 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 | */
|
---|
| 26 | const pickIndexes = curry((indexes, list) =>
|
---|
| 27 | filterIndexed(containsIndex(indexes), list)
|
---|
| 28 | );
|
---|
| 29 |
|
---|
| 30 | export default pickIndexes;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.