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

Unified Diff: lib/src/stream_sink_transformer.dart

Issue 1947923003: Add APIs for asserting the types of transformers. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes 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/async.dart ('k') | lib/src/stream_sink_transformer/typed.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/stream_sink_transformer.dart
diff --git a/lib/src/stream_sink_transformer.dart b/lib/src/stream_sink_transformer.dart
index 6cde04a7f2b663f9da98a2d0db4ab3bccdef538e..d40bc4b76d84427dad35b3646a535af47b9e3203 100644
--- a/lib/src/stream_sink_transformer.dart
+++ b/lib/src/stream_sink_transformer.dart
@@ -6,6 +6,7 @@ import 'dart:async';
import 'stream_sink_transformer/handler_transformer.dart';
import 'stream_sink_transformer/stream_transformer_wrapper.dart';
+import 'stream_sink_transformer/typed.dart';
/// A [StreamSinkTransformer] transforms the events being passed to a sink.
///
@@ -45,4 +46,17 @@ abstract class StreamSinkTransformer<S, T> {
/// Creates a new sink. When events are passed to the returned sink, it will
/// transform them and pass the transformed versions to [sink].
StreamSink<S> bind(StreamSink<T> sink);
+
+ /// Creates a wrapper that coerces the type of [transformer].
+ ///
+ /// This soundly converts a [StreamSinkTransformer] to a
+ /// `StreamSinkTransformer<S, T>`, regardless of its original generic type.
+ /// This means that calls to [StreamSink.add] on the returned sink may throw a
+ /// [CastError] if the argument type doesn't match the reified type of the
+ /// sink.
+ static StreamSinkTransformer/*<S, T>*/ typed/*<S, T>*/(
+ StreamSinkTransformer transformer) =>
+ transformer is StreamSinkTransformer/*<S, T>*/
+ ? transformer
+ : new TypeSafeStreamSinkTransformer(transformer);
}
« no previous file with comments | « lib/async.dart ('k') | lib/src/stream_sink_transformer/typed.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698