1 var createAggregator = require('../internal/createAggregator');
4 * Creates an object composed of keys generated from the results of running
5 * each element of `collection` through `iteratee`. The corresponding value
6 * of each key is the last element responsible for generating the key. The
7 * iteratee function is bound to `thisArg` and invoked with three arguments:
8 * (value, index|key, collection).
10 * If a property name is provided for `iteratee` the created `_.property`
11 * style callback returns the property value of the given element.
13 * If a value is also provided for `thisArg` the created `_.matchesProperty`
14 * style callback returns `true` for elements that have a matching property
15 * value, else `false`.
17 * If an object is provided for `iteratee` the created `_.matches` style
18 * callback returns `true` for elements that have the properties of the given
19 * object, else `false`.
23 * @category Collection
24 * @param {Array|Object|string} collection The collection to iterate over.
25 * @param {Function|Object|string} [iteratee=_.identity] The function invoked
27 * @param {*} [thisArg] The `this` binding of `iteratee`.
28 * @returns {Object} Returns the composed aggregate object.
32 * { 'dir': 'left', 'code': 97 },
33 * { 'dir': 'right', 'code': 100 }
36 * _.indexBy(keyData, 'dir');
37 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
39 * _.indexBy(keyData, function(object) {
40 * return String.fromCharCode(object.code);
42 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
44 * _.indexBy(keyData, function(object) {
45 * return this.fromCharCode(object.code);
47 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
49 var indexBy = createAggregator(function(result, value, key) {
53 module.exports = indexBy;