Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map with Object #689

Closed
allevo opened this issue Dec 28, 2014 · 4 comments
Closed

map with Object #689

allevo opened this issue Dec 28, 2014 · 4 comments
Labels

Comments

@allevo
Copy link

allevo commented Dec 28, 2014

I'm very happy if async can accept an Object as first parameter of map. The behaviour is like parallel, the result is an object with the same keys of the input.

Are you interested in?

@Sitin
Copy link

Sitin commented Dec 29, 2014

I support this idea. Lodash support this feature.
The question is: what to do with getters/setters and freezes. Should we recreate them as well? Any ideas?

@allevo
Copy link
Author

allevo commented Dec 29, 2014

The idea is to iterate over all keys of object and map the values without creating as result an object with special property. This is to avoid any kind of hellhounds or side effect!

@aearly
Copy link
Collaborator

aearly commented Jan 7, 2015

As a workaround, you can convert your object to an array of [key, value] tuples and then zip the result back up. Easy with _.pairs and _.zipObject, if you're using Lodash.

async.map(_.pairs(obj), function (tuple, cb) {
  var key = tuple[0];
  var value = tuple[1];
  // do something with key and value
  //..
  cb(null, [key, newValue]);
}, function (err, result) {
  if (err) return callback(err);
  callback(null, _.zipObject(result));
})

@aearly aearly added the feature label May 19, 2015
@aearly
Copy link
Collaborator

aearly commented May 19, 2015

Dupe of #321

@aearly aearly closed this as completed May 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants