diff --git a/CHANGELOG.md b/CHANGELOG.md index 03fff02..2577503 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 2.0.4 + +* Add support for Dart 2.0 library changes to Stream and StreamTransformer. + Changed classes that implement `StreamTransformer` to extend + `StreamTransformerBase`, and changed signatures of `firstWhere`, `lastWhere`, + and `singleWhere` on classes extending `Stream`. See + also [issue 31847][sdk#31847]. + + [sdk#31847]: https://github.com/dart-lang/sdk/issues/31847 + ## 2.0.3 * Fix a bug in `StreamQueue.startTransaction()` and related methods when diff --git a/lib/src/result/capture_transformer.dart b/lib/src/result/capture_transformer.dart index 71e8a00..5933f0c 100644 --- a/lib/src/result/capture_transformer.dart +++ b/lib/src/result/capture_transformer.dart @@ -11,7 +11,7 @@ import 'capture_sink.dart'; /// /// The result of the transformation is a stream of [Result] values and no /// error events. Exposed by [Result.captureStream]. -class CaptureStreamTransformer implements StreamTransformer> { +class CaptureStreamTransformer extends StreamTransformerBase> { const CaptureStreamTransformer(); Stream> bind(Stream source) { diff --git a/lib/src/result/release_transformer.dart b/lib/src/result/release_transformer.dart index fc9278d..01865cc 100644 --- a/lib/src/result/release_transformer.dart +++ b/lib/src/result/release_transformer.dart @@ -8,7 +8,7 @@ import 'result.dart'; import 'release_sink.dart'; /// A transformer that releases result events as data and error events. -class ReleaseStreamTransformer implements StreamTransformer, T> { +class ReleaseStreamTransformer extends StreamTransformerBase, T> { const ReleaseStreamTransformer(); Stream bind(Stream> source) { diff --git a/lib/src/single_subscription_transformer.dart b/lib/src/single_subscription_transformer.dart index fcd6b06..f590860 100644 --- a/lib/src/single_subscription_transformer.dart +++ b/lib/src/single_subscription_transformer.dart @@ -13,7 +13,7 @@ import 'dart:async'; /// This also casts the source stream's events to type `T`. If the cast fails, /// the result stream will emit a [CastError]. This behavior is deprecated, and /// should not be relied upon. -class SingleSubscriptionTransformer implements StreamTransformer { +class SingleSubscriptionTransformer extends StreamTransformerBase { const SingleSubscriptionTransformer(); Stream bind(Stream stream) { diff --git a/lib/src/typed/stream.dart b/lib/src/typed/stream.dart index a467115..b3b0513 100644 --- a/lib/src/typed/stream.dart +++ b/lib/src/typed/stream.dart @@ -53,14 +53,18 @@ class TypeSafeStream extends Stream { Stream expand(Iterable convert(T value)) => _stream.expand(_validateType(convert)); - Future firstWhere(bool test(T element), {Object defaultValue()}) => - _stream.firstWhere(_validateType(test), defaultValue: defaultValue); - - Future lastWhere(bool test(T element), {Object defaultValue()}) => - _stream.lastWhere(_validateType(test), defaultValue: defaultValue); - - Future singleWhere(bool test(T element)) async => - (await _stream.singleWhere(_validateType(test))) as T; + Future firstWhere(bool test(T element), + {Object defaultValue(), T orElse()}) => + _stream.firstWhere(_validateType(test), + defaultValue: defaultValue, orElse: orElse); + + Future lastWhere(bool test(T element), + {Object defaultValue(), T orElse()}) => + _stream.lastWhere(_validateType(test), + defaultValue: defaultValue, orElse: orElse); + + Future singleWhere(bool test(T element), {T orElse()}) async => + await _stream.singleWhere(_validateType(test), orElse: orElse); Future fold(S initialValue, S combine(S previous, T element)) => _stream.fold( diff --git a/lib/src/typed_stream_transformer.dart b/lib/src/typed_stream_transformer.dart index 98d5e70..cb63311 100644 --- a/lib/src/typed_stream_transformer.dart +++ b/lib/src/typed_stream_transformer.dart @@ -20,7 +20,7 @@ StreamTransformer typedStreamTransformer( /// A wrapper that coerces the type of the stream returned by an inner /// transformer. -class _TypeSafeStreamTransformer implements StreamTransformer { +class _TypeSafeStreamTransformer extends StreamTransformerBase { final StreamTransformer _inner; _TypeSafeStreamTransformer(this._inner); diff --git a/pubspec.yaml b/pubspec.yaml index 3fd3bbb..3b9bac4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: async -version: 2.0.3 +version: 2.0.4 author: Dart Team description: Utility functions and classes related to the 'dart:async' library. homepage: https://www.github.com/dart-lang/async environment: - sdk: ">=2.0.0-dev.15.0 <2.0.0" + sdk: ">=2.0.0-dev.23.0 <2.0.0" dependencies: collection: "^1.5.0" dev_dependencies: