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