async.map, but with an index like async.eachOf

Created on 23 Jan 2017  ·  8Comments  ·  Source: caolan/async

Hey all

Looking through the docs, I am looking for async.map, but with the index of the iteratee passed to the callback.
With async.each, the analogue is async.eachOf. But I don't see async.mapOf or what not.

Is there such a thing? Let me know if you need more info, thanks!

Most helpful comment

We're ok 👍 Anyway here's what i tried to get the data back:

var async = require('async');

async.forEachOf(['a', 'b', 'c'], function () {

  console.log(arguments[1]);
});

All 8 comments

Hey :) Is what you need similar to this answer - http://stackoverflow.com/a/31821896 . Maybe you can create an alias/copy method that just calls async.forEachOf whenever you call async.mapOf, if you find that name more fitting.

@jpalala what's up Joe! let me give that a shot, how are things going?

does async.forEachOfpass data to the final callback like async.map?

We're ok 👍 Anyway here's what i tried to get the data back:

var async = require('async');

async.forEachOf(['a', 'b', 'c'], function () {

  console.log(arguments[1]);
});

~forEachOf and family don't pass the results to the callback. If you want the key, you could do something like:~

async.forEach(_.entries(obj), ( [key, value], next ) => {
  // do whatever
}, done);

~Keep in mind, this will return an array, and the order will not be guaranteed. You'd have to build a result object manually.~

EDIT: use mapValues

why not mapValues?

async.mapValues( (val, key, next) => {
    // do whatever
}, (err, obj) => {
    let result = _.toArray(obj);
});

@ex1st huh that might work!

Yeah, disregard what I said, mapValues is exactly what you want.

Was this page helpful?
0 / 5 - 0 ratings