-
Notifications
You must be signed in to change notification settings - Fork 26
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
Promise.map
and Promise.filter
#37
Open
arthurschreiber
wants to merge
17
commits into
lgierth:master
Choose a base branch
from
arthurschreiber:arthur/map-and-filter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Promise.map
and Promise.filter
#37
arthurschreiber
wants to merge
17
commits into
lgierth:master
from
arthurschreiber:arthur/map-and-filter
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@dylanahsmith Heyo! 👋 Do you have any opinion regarding these extensions? I had to pin the version of There is also a few mutants not getting killed in the mutation tests, but I'm not sure how to properly fix those. Any idea? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds 2 new methods,
Promise.map
andPromise.filter
, heavily inspired by the equally named methods from the greatbluebird.js
Promise library for JavaScript.Promise.map
Promise.map
is similar toPromise.all
, except that the values resolved from the input enumerable will be mapped using the provided block. This block can either returnPromise
or non-Promise
objects. The promise returned byPromise.map
will be resolved once all values have been mapped.Example
Without
Promise.map
, the same thing can be achieved like this:Advantages
Besides the improved ease-of-use, the native
Promise.map
has better performance over the solution build onPromise.all
.Promise.map
can interleave the process of resolving values and mapping them to their final value, while these are two separate steps in the alternative version usingPromise.all
.Promise.filter
Promise.filter
allows filtering an enumerable containingPromise
and/or non-Promise
values, based on the given filter block. The filter block can return eitherPromise
or non-Promise
values.Example
Without
Promise.filter
, the same thing can be achieved like this:Advantages
Again, the version built on
Promise.filter
is a lot easier to understand. Similar toPromise.map
,Promise.filter
can perform the initial value resolution and filtering process at the same time, where as the version built onPromise.all
performs two discrete steps.