source: node_modules/ramda/es/indexBy.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 reduceBy from "./reduceBy.js";
2/**
3 * Given a function that generates a key, turns a list of objects into an
4 * object indexing the objects by the given key. Note that if multiple
5 * objects generate the same value for the indexing key only the last value
6 * will be included in the generated object.
7 *
8 * Acts as a transducer if a transformer is given in list position.
9 *
10 * @func
11 * @memberOf R
12 * @since v0.19.0
13 * @category List
14 * @typedefn Idx = String | Int | Symbol
15 * @sig Idx a => (b -> a) -> [b] -> {a: b}
16 * @param {Function} fn Function :: a -> Idx
17 * @param {Array} array The array of objects to index
18 * @return {Object} An object indexing each array element by the given property.
19 * @see R.groupBy
20 * @example
21 *
22 * const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
23 * R.indexBy(R.prop('id'), list);
24 * //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
25 */
26
27var indexBy =
28/*#__PURE__*/
29reduceBy(function (acc, elem) {
30 return elem;
31}, null);
32export default indexBy;
Note: See TracBrowser for help on using the repository browser.