-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
async.map which works on objects #374
Comments
+1 |
+1 For now I use this wrapper function asyncObjectMap( obj, func, cb ) {
var i, arr = [], keys = Object.keys( obj );
for ( i = 0; i < keys.length; i += 1 ) {
arr[i] = obj[keys[i]];
}
async.map( arr, func, function( err, data ) {
if ( err ) { return cb( err ); }
var res = {};
for ( i = 0; i < data.length; i += 1 ) {
res[keys[i]] = data[i];
}
return cb( err, res );
} );
}
// test
asyncObjectMap(
{ a: 1, b: 2 },
function( item, cb ) {
console.log( item );
cb( null, item );
},
console.log
); |
It would be good to note the resolution of the ticket here -- reading through commit messages to find the answer is often not as easy as it sounds. Was this implemented or rejected? |
Great -- thanks. |
Another Version of @glukki 's Wrapper:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had a use case just now for async.map which iterates on the values of an object, and whose callback has a new object with the original keys pointing to the translated values of the same keys.
async.map as it exists doesn't allow this, and I couldn't see another method which does the same (please let me know if I missed it).
I think it'd be useful feature.
In the mean time, I faked it with underscore by doing
async.map(_.values(obj), ...
and then in the callback using_.object(_.keys(obj), transformed)
.The text was updated successfully, but these errors were encountered: