-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
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