Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: lib/stream_channel.dart

Issue 1966853003: Add type-coercion functions. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/transformer/typed.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/stream_channel.dart
diff --git a/lib/stream_channel.dart b/lib/stream_channel.dart
index b89845d0557615f0a839ba7381caf2d3c32bb784..3615d2129510f38bcdfa43d8bdc7584b7049936c 100644
--- a/lib/stream_channel.dart
+++ b/lib/stream_channel.dart
@@ -109,6 +109,13 @@ abstract class StreamChannel<T> {
/// Returns a copy of [this] with [sink] replaced by [change]'s return
/// value.
StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink));
+
+ /// Returns a copy of [this] with the generic type coerced to [S].
+ ///
+ /// If any events emitted by [stream] aren't of type [S], they're converted
+ /// into [CastError] events. Similarly, if any events are added to [sync] that
+ /// aren't of type [S], a [CastError] is thrown.
+ StreamChannel/*<S>*/ cast/*<S>*/();
}
/// An implementation of [StreamChannel] that simply takes a stream and a sink
@@ -145,4 +152,7 @@ abstract class StreamChannelMixin<T> implements StreamChannel<T> {
StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) =>
new StreamChannel(stream, change(sink));
+
+ StreamChannel/*<S>*/ cast/*<S>*/() => new StreamChannel(
+ DelegatingStream.typed(stream), DelegatingStreamSink.typed(sink));
}
« no previous file with comments | « lib/src/transformer/typed.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698