-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Match [].some()
behavior
#17
Comments
Note: When |
This is my local implementation of a boolean p-some for Refined GitHub: export default async function pSome(iterable: Iterable<Promise<unknown>>): Promise<boolean> {
return new Promise(resolve => {
for (const promise of iterable) {
(async () => {
if (await promise) {
resolve(true);
}
})();
}
void Promise.allSettled(iterable).then(() => {
resolve(false);
});
});
} |
While the naming is unfortunately because of Maybe do a named export for this behavior or a separate package? |
Before this point: 7 years Never too late 😃
As long as there's an easy upgrade path I don't see the problem with it.
Are you talking about https://github.com/tc39/proposal-iterator-helpers#somefn You may be right, it might be possible to use |
Counterpoint: No one needed what you propose in 7 years of its existence. |
What is the upgrade path? If we change from returning the values to returning a boolean, I don't really see how the user could even upgrade. |
It's more likely that they settled for its booleanish equivalence and there are plenty of bugs caused by |
I only use it for the current behavior. |
Totally irrelevant, but I find the name |
As for the modeling, it looks this matches Bluebird's .some() method exactly so I'll close this issue. |
I think I see two main differences:
count
is required, while it should likely just default to 1[].some(() => true)
just returnsfalse
whilepSome([], {count:1})
will throwp-some
is acting as a limitedfilter
rather than a boolean-returning functionI'd suggest moving this limiting behavior to https://github.com/sindresorhus/p-filter or rethink this this pattern with the upcoming iterator helpers: https://github.com/tc39/proposal-iterator-helpers#takelimit
For example:
[...promises].filter(filtererFn).take(2)
The text was updated successfully, but these errors were encountered: