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

Collection#find method #3948

Closed
DartBot opened this issue Jul 1, 2012 · 6 comments
Closed

Collection#find method #3948

DartBot opened this issue Jul 1, 2012 · 6 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

Comments

@DartBot
Copy link

DartBot commented Jul 1, 2012

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.

@lrhn
Copy link
Member

lrhn commented Jul 1, 2012

A find should definitely be there. I'd prefer to call it "findFirst", since it's less ambiguous.
Good point about "filter"/"findAll".


Set owner to @lrhn.
Added Accepted label.

@lrhn
Copy link
Member

lrhn commented Jul 1, 2012

Added Area-Library label.

@sethladd
Copy link
Contributor

Added this to the Later milestone.

@kevmoo
Copy link
Member

kevmoo commented Nov 27, 2012

I like the .NET model w/ an extension method E first([bool predicate(E item)])

w/out optional argument, just returns the first element
w/ argument, uses the predicate

Doesn't align w/ 'first' as a property, though.

I'd like to see this in Iterable, not just Collection

@lrhn
Copy link
Member

lrhn commented Mar 15, 2013

There is now an Iterable.firstWhere doing exactly this (and a lastWhere too!)

@lrhn
Copy link
Member

lrhn commented Mar 15, 2013

Added Fixed label.

@DartBot DartBot added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Mar 15, 2013
@DartBot DartBot added this to the Later milestone Mar 15, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
Projects
None yet
Development

No branches or pull requests

4 participants