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

Support ES6's Iterators #839

Closed
dhritzkiv opened this issue Jul 4, 2015 · 4 comments
Closed

Support ES6's Iterators #839

dhritzkiv opened this issue Jul 4, 2015 · 4 comments
Labels

Comments

@dhritzkiv
Copy link
Contributor

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

@aearly
Copy link
Collaborator

aearly commented Jul 6, 2015

I like the idea. You can get decent support today, just by using the spread operator:

async.map([...numberMap], function (item, callback) {...

async.map always returns an array, though. We'd have to create special mapping functions for the various collection types, similar to _.map vs. _.mapValues in lodash, for Arrays vs. Objects.

@megawac
Copy link
Collaborator

megawac commented Jul 19, 2015

👍 it'd be relatively easy to support via some keyIterator post #847

@aearly aearly changed the title Support ES6's Map and Set Support ES6's Iterators Mar 21, 2016
@ex1st
Copy link

ex1st commented Mar 22, 2016

New PR for generators #1074

@aearly
Copy link
Collaborator

aearly commented Mar 23, 2016

Closed by #1074!

@aearly aearly closed this as completed Mar 23, 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

4 participants