Skip to content

Support ES6's Iterators #839

@dhritzkiv

Description

@dhritzkiv

ES6's Map and Sets feel like they could fit as an input data type, as they can be iterated over easily.
I found myself looking to use async with a Map earlier today, but had to convert it to an object and back.

Example with a Map:

const numberMap = new Map();
var obj1 = {num: 1};
var obj2 = {num: 2};
numberMap.set(1, obj1);
numberMap.set(2, obj2);

async.map(numberMap, function(item, callback) {
    item.num *= 2;
    callback(null, item);
}, function(err, newNumberMap) {
   console.log(newNumberMap)
   //Map { 1 => { num: 2 }, 2 => { num: 4 } }
   console.log(newNumberMap instanceof Map)
   //true;
});

Example with a Set:

const numberObjectSet = new Set();
var obj1 = {num: 1};
var obj2 = {num: 2};
numberObjectSet.add(obj1);
numberObjectSet.add(obj2);

async.map(numberObjectSet, function(item, callback) {
    item.num *= 2;
    callback(null, item);
}, function(err, newNumberObjectSet) {
   console.log(newNumberObjectSet);
   //Set { { num: 2 }, { num: 4} }
   console.log(newNumberObjectSet instanceof Set)
   //true;
});

Possibly related to #579

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions