1 | var reduceBy =
|
2 | /*#__PURE__*/
|
3 | require("./reduceBy");
|
4 | /**
|
5 | * Given a function that generates a key, turns a list of objects into an
|
6 | * object indexing the objects by the given key. Note that if multiple
|
7 | * objects generate the same value for the indexing key only the last value
|
8 | * will be included in the generated object.
|
9 | *
|
10 | * Acts as a transducer if a transformer is given in list position.
|
11 | *
|
12 | * @func
|
13 | * @memberOf R
|
14 | * @since v0.19.0
|
15 | * @category List
|
16 | * @sig (a -> String) -> [{k: v}] -> {k: {k: v}}
|
17 | * @param {Function} fn Function :: a -> String
|
18 | * @param {Array} array The array of objects to index
|
19 | * @return {Object} An object indexing each array element by the given property.
|
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 |
|
27 |
|
28 | var indexBy =
|
29 | /*#__PURE__*/
|
30 | reduceBy(function (acc, elem) {
|
31 | return elem;
|
32 | }, null);
|
33 | module.exports = indexBy; |
\ | No newline at end of file |