-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Collection#find method #3948
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
Comments
Added Area-Library label. |
Added this to the Later milestone. |
I like the .NET model w/ an extension method E first([bool predicate(E item)]) w/out optional argument, just returns the first element Doesn't align w/ 'first' as a property, though. I'd like to see this in Iterable, not just Collection |
There is now an Iterable.firstWhere doing exactly this (and a lastWhere too!) |
Added Fixed label. |
This issue was originally filed by @seaneagan
A method on Collection to find the first of it's elements which matches a predicate would be useful:
E find(bool predicate(E item)) {
var filtered = filter(predicate);
if(filtered.isEmpty) return null; // throw instead ?
return filtered.iterator().next();
};
it might also make sense to rename Collection#filter to Collection#findAll since "filter" seems to have a mutative connotation.
The text was updated successfully, but these errors were encountered: