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

Implement map() #3

Open
julien-f opened this issue Mar 3, 2016 · 6 comments
Open

Implement map() #3

julien-f opened this issue Mar 3, 2016 · 6 comments

Comments

@julien-f
Copy link
Collaborator

julien-f commented Mar 3, 2016

iterable::map(mapper, [ opts ]).then((collection) => {
  // Like iterable::all(), collection is an object if iterable
  // was a plain object, a map otherwise.
})
  • wait for the iterable promise to be resolved
  • execute mapper on an entry ASAP
  • support a concurrency option defaulting to Infinity
@perrin4869
Copy link
Contributor

Hm... I noticed that you removed the map from 0.19.0. It was actually quite useful.
Did it have any missing features? Do you plan to return it?

@julien-f
Copy link
Collaborator Author

Hi,

It was removed because I wasn't satisfied with its features and API.

What features were you using that is not available via a simple

await Promise.all(Array.from(iterable, async item => {
 // …
}))

@perrin4869
Copy link
Contributor

Well, I had code that looked like this:

return Promise.all([manager.getAllUserIds(), getUserIds(processId)])
      .then(apply(difference))
      ::map(disconnecter.disconnect(?, 0));

Using @babel/proposal-partial-application and @babel/proposal-function-bind. Without ::map I would be left with something like:

return Promise.all([manager.getAllUserIds(), getUserIds(processId)])
      .then(apply(difference))
      .then(ids => Promise.all(ids.map(disconnecter.disconnect(?, 0))));

Not the end of the world but I really like the syntax with ::map

@julien-f
Copy link
Collaborator Author

I like this syntax as well, unfortunately it looks like it's never gonna be standardized, therefore I'll be moving away from it.

If you want to keep using it, you can use a simple implementation like:

function map(cb) {
  return Promise.all(Array.from(this, cb));
}

@perrin4869
Copy link
Contributor

Well, more recently there has been some progress as far as this proposal goes: https://github.com/tc39/proposal-extensions
Still just in stage 1 though

@julien-f
Copy link
Collaborator Author

Thanks for this info, I'll keep an eye on it 🙂

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

No branches or pull requests

2 participants