map.js

  1. import doParallel from './internal/doParallel';
  2. import map from './internal/map';
  3. /**
  4. * Produces a new collection of values by mapping each value in `coll` through
  5. * the `iteratee` function. The `iteratee` is called with an item from `coll`
  6. * and a callback for when it has finished processing. Each of these callback
  7. * takes 2 arguments: an `error`, and the transformed item from `coll`. If
  8. * `iteratee` passes an error to its callback, the main `callback` (for the
  9. * `map` function) is immediately called with the error.
  10. *
  11. * Note, that since this function applies the `iteratee` to each item in
  12. * parallel, there is no guarantee that the `iteratee` functions will complete
  13. * in order. However, the results array will be in the same order as the
  14. * original `coll`.
  15. *
  16. * If `map` is passed an Object, the results will be an Array. The results
  17. * will roughly be in the order of the original Objects' keys (but this can
  18. * vary across JavaScript engines).
  19. *
  20. * @name map
  21. * @static
  22. * @memberOf module:Collections
  23. * @method
  24. * @category Collection
  25. * @param {Array|Iterable|Object} coll - A collection to iterate over.
  26. * @param {AsyncFunction} iteratee - An async function to apply to each item in
  27. * `coll`.
  28. * The iteratee should complete with the transformed item.
  29. * Invoked with (item, callback).
  30. * @param {Function} [callback] - A callback which is called when all `iteratee`
  31. * functions have finished, or an error occurs. Results is an Array of the
  32. * transformed items from the `coll`. Invoked with (err, results).
  33. * @example
  34. *
  35. * async.map(['file1','file2','file3'], fs.stat, function(err, results) {
  36. * // results is now an array of stats for each file
  37. * });
  38. */
  39. export default doParallel(map);