'Leaf Petersen' via Dart Misc
2018-03-01 01:13:01 UTC
*What is changing?*
As part of the migration of the Dart core libraries to Dart 2, we are
changing the signatures of `Stream.firstWhere` and `Stream.lastWhere` to be
more usable in a typed fashion.
We have already landed changes moving the signature of `firstWhere` from
Future firstWhere(bool test(T element), {dynamic defaultValue()}) {
to
Future<T> firstWhere(bool test(T element), {dynamic defaultValue(), T
orElse()}) {
and similarly for `lastWhere`. This was done to allow incremental
migration: `orElse` is intended to replace `defaultValue`.
As the last step of this process, we are now deprecating and will soon be
removing the `defaultValue` parameter to both methods.
Future<T> firstWhere(bool test(T element), {T orElse()}) {
*What will break?*
If you have code which calls `Stream.firstWhere` or `Stream.lastWhere` or
the equivalent methods on classes implementing `Stream` from
`package:async`, *and* you pass a defaultValue argument, then you will soon
begin receiving deprecation warnings, and soon after your code will break.
*How do I fix it?*
Anywhere you currently pass `defaultValue: <someFunction>` to one of these
methods, you should change your code to pass `orElse: <someFunction>`.
You can (and should!) do this now, assuming that you are on an up to date
version of flutter, or are using a Dart SDK later than 2.0.0-dev.23.0 .
This rollout was staged so that you can fix your code now and never be in a
broken state.
It is possible (though fairly unlikely) that changing your code to use
`orElse` will cause new analyzer warnings, since inference will now be
doing a better job of propagating types. You can always get back to the
original inference state by changing code that looks like:
```
s.firstWhere(f, defaultValue: e);
```
into
```
dynamic defaultValueFn() => e
s.firstWhere(f, orElse: defaultValueFn);
```
*Why is this change being made?*
Making `orElse` strongly typed allows inference to work better with these
APIs, making it more likely that the analyzer can help catch errors, and
making it less likely that your code will fail Dart 2 runtime checks.
I will update here when this change lands. Please reach out to me here or
offline with any concerns, and/or with help resolving any issues after this
change has landed.
thanks,
-leaf
As part of the migration of the Dart core libraries to Dart 2, we are
changing the signatures of `Stream.firstWhere` and `Stream.lastWhere` to be
more usable in a typed fashion.
We have already landed changes moving the signature of `firstWhere` from
Future firstWhere(bool test(T element), {dynamic defaultValue()}) {
to
Future<T> firstWhere(bool test(T element), {dynamic defaultValue(), T
orElse()}) {
and similarly for `lastWhere`. This was done to allow incremental
migration: `orElse` is intended to replace `defaultValue`.
As the last step of this process, we are now deprecating and will soon be
removing the `defaultValue` parameter to both methods.
Future<T> firstWhere(bool test(T element), {T orElse()}) {
*What will break?*
If you have code which calls `Stream.firstWhere` or `Stream.lastWhere` or
the equivalent methods on classes implementing `Stream` from
`package:async`, *and* you pass a defaultValue argument, then you will soon
begin receiving deprecation warnings, and soon after your code will break.
*How do I fix it?*
Anywhere you currently pass `defaultValue: <someFunction>` to one of these
methods, you should change your code to pass `orElse: <someFunction>`.
You can (and should!) do this now, assuming that you are on an up to date
version of flutter, or are using a Dart SDK later than 2.0.0-dev.23.0 .
This rollout was staged so that you can fix your code now and never be in a
broken state.
It is possible (though fairly unlikely) that changing your code to use
`orElse` will cause new analyzer warnings, since inference will now be
doing a better job of propagating types. You can always get back to the
original inference state by changing code that looks like:
```
s.firstWhere(f, defaultValue: e);
```
into
```
dynamic defaultValueFn() => e
s.firstWhere(f, orElse: defaultValueFn);
```
*Why is this change being made?*
Making `orElse` strongly typed allows inference to work better with these
APIs, making it more likely that the analyzer can help catch errors, and
making it less likely that your code will fail Dart 2 runtime checks.
I will update here when this change lands. Please reach out to me here or
offline with any concerns, and/or with help resolving any issues after this
change has landed.
thanks,
-leaf
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.