metasync
metasync copied to clipboard
Add support for iterable
I propose to add support for everything that implements iterable or iterator protocols to such methods as:
-
metasync.map()
-
metasync.filter()
-
metasync.each()
-
metasync.series()
-
metasync.find()
-
metasync.every()
-
metasync.some()
-
metasync.for()
Also, it may be useful for these functions to support objects that doesn't implement any of the above protocols, this way they will be iterated over pairs of [key, value]
.
@nechaido what is the difference between .for
and this .each
?
@tshemsedinov for
is used to create an ArrayChain
.
@tshemsedinov here are some examples.
metasync.for
:
const set = new Set([1, 2, 3, 4]);
metasync
.for(set)
.map((item, callback) => callback(null, item * 2))
.reduce((previous, current, callback) => callback(null, previous + current))
.fetch((error, result) => {
if (error) {
console.error(error);
return;
}
console.log(result);
});
metasync.each
:
const set = new Set([1, 2, 3, 4]);
metasync.each(
set,
(item, callback) => {
console.log(item * 2);
callback(null);
},
(error) => {
if (error) {
console.error(error);
}
}
);