Skip to content

Add forMapOf like forEachOf #1133

@alinex

Description

@alinex

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions