metasync icon indicating copy to clipboard operation
metasync copied to clipboard

Add support for iterable

Open nechaido opened this issue 6 years ago • 3 comments

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 avatar Feb 23 '18 12:02 nechaido

@nechaido what is the difference between .for and this .each ?

tshemsedinov avatar Feb 23 '18 22:02 tshemsedinov

@tshemsedinov for is used to create an ArrayChain.

nechaido avatar Feb 26 '18 11:02 nechaido

@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);
    }
  }
);

nechaido avatar Feb 27 '18 12:02 nechaido