1
|
'use strict';
|
2
|
|
3
|
Object.defineProperty(exports, "__esModule", {
|
4
|
value: true
|
5
|
});
|
6
|
|
7
|
var _doLimit = require('./internal/doLimit');
|
8
|
|
9
|
var _doLimit2 = _interopRequireDefault(_doLimit);
|
10
|
|
11
|
var _groupByLimit = require('./groupByLimit');
|
12
|
|
13
|
var _groupByLimit2 = _interopRequireDefault(_groupByLimit);
|
14
|
|
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
|
|
17
|
/**
|
18
|
* Returns a new object, where each value corresponds to an array of items, from
|
19
|
* `coll`, that returned the corresponding key. That is, the keys of the object
|
20
|
* correspond to the values passed to the `iteratee` callback.
|
21
|
*
|
22
|
* Note: Since this function applies the `iteratee` to each item in parallel,
|
23
|
* there is no guarantee that the `iteratee` functions will complete in order.
|
24
|
* However, the values for each key in the `result` will be in the same order as
|
25
|
* the original `coll`. For Objects, the values will roughly be in the order of
|
26
|
* the original Objects' keys (but this can vary across JavaScript engines).
|
27
|
*
|
28
|
* @name groupBy
|
29
|
* @static
|
30
|
* @memberOf module:Collections
|
31
|
* @method
|
32
|
* @category Collection
|
33
|
* @param {Array|Iterable|Object} coll - A collection to iterate over.
|
34
|
* @param {AsyncFunction} iteratee - An async function to apply to each item in
|
35
|
* `coll`.
|
36
|
* The iteratee should complete with a `key` to group the value under.
|
37
|
* Invoked with (value, callback).
|
38
|
* @param {Function} [callback] - A callback which is called when all `iteratee`
|
39
|
* functions have finished, or an error occurs. Result is an `Object` whoses
|
40
|
* properties are arrays of values which returned the corresponding key.
|
41
|
* @example
|
42
|
*
|
43
|
* async.groupBy(['userId1', 'userId2', 'userId3'], function(userId, callback) {
|
44
|
* db.findById(userId, function(err, user) {
|
45
|
* if (err) return callback(err);
|
46
|
* return callback(null, user.age);
|
47
|
* });
|
48
|
* }, function(err, result) {
|
49
|
* // result is object containing the userIds grouped by age
|
50
|
* // e.g. { 30: ['userId1', 'userId3'], 42: ['userId2']};
|
51
|
* });
|
52
|
*/
|
53
|
exports.default = (0, _doLimit2.default)(_groupByLimit2.default, Infinity);
|
54
|
module.exports = exports['default'];
|