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

Add support for iterable #313

Open
nechaido opened this issue Feb 23, 2018 · 3 comments
Open

Add support for iterable #313

nechaido opened this issue Feb 23, 2018 · 3 comments
Assignees

Comments

@nechaido
Copy link
Member

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].

@tshemsedinov
Copy link
Member

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

@nechaido
Copy link
Member Author

@tshemsedinov for is used to create an ArrayChain.

@nechaido
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants