1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _map2 = require('./internal/map');
|
8 |
|
9 | var _map3 = _interopRequireDefault(_map2);
|
10 |
|
11 | var _eachOf = require('./eachOf');
|
12 |
|
13 | var _eachOf2 = _interopRequireDefault(_eachOf);
|
14 |
|
15 | var _awaitify = require('./internal/awaitify');
|
16 |
|
17 | var _awaitify2 = _interopRequireDefault(_awaitify);
|
18 |
|
19 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
20 |
|
21 | /**
|
22 | * Produces a new collection of values by mapping each value in `coll` through
|
23 | * the `iteratee` function. The `iteratee` is called with an item from `coll`
|
24 | * and a callback for when it has finished processing. Each of these callback
|
25 | * takes 2 arguments: an `error`, and the transformed item from `coll`. If
|
26 | * `iteratee` passes an error to its callback, the main `callback` (for the
|
27 | * `map` function) is immediately called with the error.
|
28 | *
|
29 | * Note, that since this function applies the `iteratee` to each item in
|
30 | * parallel, there is no guarantee that the `iteratee` functions will complete
|
31 | * in order. However, the results array will be in the same order as the
|
32 | * original `coll`.
|
33 | *
|
34 | * If `map` is passed an Object, the results will be an Array. The results
|
35 | * will roughly be in the order of the original Objects' keys (but this can
|
36 | * vary across JavaScript engines).
|
37 | *
|
38 | * @name map
|
39 | * @static
|
40 | * @memberOf module:Collections
|
41 | * @method
|
42 | * @category Collection
|
43 | * @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
|
44 | * @param {AsyncFunction} iteratee - An async function to apply to each item in
|
45 | * `coll`.
|
46 | * The iteratee should complete with the transformed item.
|
47 | * Invoked with (item, callback).
|
48 | * @param {Function} [callback] - A callback which is called when all `iteratee`
|
49 | * functions have finished, or an error occurs. Results is an Array of the
|
50 | * transformed items from the `coll`. Invoked with (err, results).
|
51 | * @returns {Promise} a promise, if no callback is passed
|
52 | * @example
|
53 | *
|
54 | * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
|
55 | * // results is now an array of stats for each file
|
56 | * });
|
57 | */
|
58 | function map(coll, iteratee, callback) {
|
59 | return (0, _map3.default)(_eachOf2.default, coll, iteratee, callback);
|
60 | }
|
61 | exports.default = (0, _awaitify2.default)(map, 3);
|
62 | module.exports = exports['default']; |
\ | No newline at end of file |