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

Stream/Iterable.firstWhere inconsistency (orElse vs. defaultValue) #22028

Closed
DartBot opened this issue Jan 8, 2015 · 8 comments
Closed

Stream/Iterable.firstWhere inconsistency (orElse vs. defaultValue) #22028

DartBot opened this issue Jan 8, 2015 · 8 comments
Assignees
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. core-2 library-async type-enhancement A request for a change that isn't a bug
Milestone

Comments

@DartBot
Copy link

DartBot commented Jan 8, 2015

This issue was originally filed by @seaneagan


I wanted to call firstWhere on a variable which could either be an Iterable or a Stream , but since I needed to have a fallback, I needed orElse / defaultValue, but since they are named differently I would have to test if the variable is an Iterable or or Stream first.

@lrhn
Copy link
Member

lrhn commented Jan 9, 2015

That's an annoying difference. Thanks for noticing!
Not something we can change right now without making a breaking change, so it'll have to be a 2.0 change if we do the rename.

Same problem for lastWhere, obviously.
I think the async version should be changed to orElse. It's shorter.


Added this to the 2.0 milestone.
Added Library-Async, Area-Library, Accepted labels.

@DartBot
Copy link
Author

DartBot commented Jan 12, 2015

This comment was originally written by @seaneagan


A related annoyance: Not being able to call map on a value which may either be a Stream or Iterable when the mapping function may return a Future, due to the split between Stream.map and Stream.mapAsync. And same issue for expand/expandAsync and Stream methods which don't allow their callbacks to return Futures e.g. firstWhere, see issue #8247 and issue #12295.

@DartBot
Copy link
Author

DartBot commented Jan 12, 2015

This comment was originally written by @seaneagan


For example, here's what I would want for Stream.firstWhere:

firstWhere(Stream stream, bool test(item), { orElse() }) async {
  await for (var i in this) {
    if (await test(i) return i;
  }
  return await orElse();
}

@DartBot
Copy link
Author

DartBot commented Jan 12, 2015

This comment was originally written by @seaneagan


Correction:

Future<T> firstWhere(test(item), { orElse() }) async {
  await for (var i in this) {
    if (await test(i) return i;
  }
  return await orElse();
}

@DartBot DartBot added Type-Defect library-async area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jan 12, 2015
@DartBot DartBot added this to the 2.0 milestone Jan 12, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed accepted labels Feb 29, 2016
@floitschG floitschG added core-2 and removed core-m labels Aug 23, 2017
@dgrove
Copy link
Contributor

dgrove commented Mar 18, 2018

Are any further changes planned here for 2.0 @lrhn?

@lrhn
Copy link
Member

lrhn commented Mar 18, 2018

This has almost been fixed, but we still need to remove the defaultValue parameter from Stream.

@dgrove dgrove modified the milestones: 2.0, Dart2 Beta 3 Mar 18, 2018
@dgrove
Copy link
Contributor

dgrove commented Apr 10, 2018

Any updates here? We are 2 days out from the Dart2 Beta 3 milestone.

@lrhn
Copy link
Member

lrhn commented Apr 10, 2018

The defaultValue parameter has been removed, so this has been fixed.

@lrhn lrhn closed this as completed Apr 10, 2018
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. core-2 library-async type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants