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 | |
---|
1 | var reduceBy =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./reduceBy.js");
|
---|
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 | * @typedefn Idx = String | Int | Symbol
|
---|
17 | * @sig Idx a => (b -> a) -> [b] -> {a: b}
|
---|
18 | * @param {Function} fn Function :: a -> Idx
|
---|
19 | * @param {Array} array The array of objects to index
|
---|
20 | * @return {Object} An object indexing each array element by the given property.
|
---|
21 | * @see R.groupBy
|
---|
22 | * @example
|
---|
23 | *
|
---|
24 | * const list = [{id: 'xyz', title: 'A'}, {id: 'abc', title: 'B'}];
|
---|
25 | * R.indexBy(R.prop('id'), list);
|
---|
26 | * //=> {abc: {id: 'abc', title: 'B'}, xyz: {id: 'xyz', title: 'A'}}
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | var indexBy =
|
---|
31 | /*#__PURE__*/
|
---|
32 | reduceBy(function (acc, elem) {
|
---|
33 | return elem;
|
---|
34 | }, null);
|
---|
35 | module.exports = indexBy; |
---|
Note:
See
TracBrowser
for help on using the repository browser.