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

Add forMapOf like forEachOf #1133

Closed
alinex opened this issue Apr 28, 2016 · 5 comments
Closed

Add forMapOf like forEachOf #1133

alinex opened this issue Apr 28, 2016 · 5 comments
Labels

Comments

@alinex
Copy link

alinex commented Apr 28, 2016

I would like to have a async.map method working on objects like the async.forEachOf does. As a working wrapper I currently use (as coffeescript):

    forMapOf = (obj, iterator, cb) ->
      # check the object
      return cb new Error "mapOf only works on objects" unless typeof obj is 'object'
      # map over object keys
      keys = Object.keys obj
      async.map keys, (key, cb) ->
        # call iterator with value and key
        iterator obj[key], key, cb
      , (err, results) ->
        return cb err if err
        # combine the results into an object again
        map = {}
        for num in [0..keys.length-1]
          map[keys[num]] = results[num]
        cb null, map

Is it possible to integrate such functionality directly with it's limit and series partners?

@aearly aearly added the feature label Apr 28, 2016
@aearly
Copy link
Collaborator

aearly commented Apr 28, 2016

I think you're better off using eachOf and family if you need the key. The other option would be to use something like _.pairs(obj) and then _.ziping the result back up when you're done.

Also note that map already works with objects, it just doesn't give you access to the key in the iteratee.

@aearly
Copy link
Collaborator

aearly commented May 17, 2016

I think we're going to separate out object functionality in to mapValues and mapKeys. See #1157

@aearly aearly closed this as completed May 17, 2016
@megawac
Copy link
Collaborator

megawac commented May 17, 2016

Brings the questions of whether the key+value should be accessible for those implementations and whether we should keep a unary version (each vs eachOf, map vs mapOf)

@aearly
Copy link
Collaborator

aearly commented May 17, 2016

I think we should pass (value, key, cb) to both, not worry about the unary case.

@alinex
Copy link
Author

alinex commented Jun 8, 2016

I could work perfectly with the behaviour in v2.0.0-rc.5, there i step over object keys without access to the key name but since v2.0.0-rc.6 i give an object and get an array back, that won't work.

I added my workarround from the first post again to get it working again!

alinex referenced this issue Jun 8, 2016
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