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

Side by Side Diff: lib/src/typed_stream_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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'delegate/stream.dart';
8
9 /// Creates a wrapper that coerces the type of [transformer].
10 ///
11 /// This soundly converts a [StreamTransformer] to a `StreamTransformer<S, T>`,
12 /// regardless of its original generic type, by asserting that the events
13 /// emitted by the transformed stream are instances of `T` whenever they're
14 /// provided. If they're not, the stream throws a [CastError].
Lasse Reichstein Nielsen 2016/05/09 19:20:12 Also say that t expects the argument to bind to be
nweiz 2016/05/09 19:31:51 This isn't really an aspect of the behavior of the
15 StreamTransformer/*<S, T>*/ typedStreamTransformer/*<S, T>*/(
16 StreamTransformer transformer) =>
17 transformer is StreamTransformer/*<S, T>*/
18 ? transformer
19 : new _TypeSafeStreamTransformer(transformer);
20
21 /// A wrapper that coerces the type of the stream returned by an inner
22 /// transformer.
23 class _TypeSafeStreamTransformer<S, T> implements StreamTransformer<S, T> {
24 final StreamTransformer _inner;
25
26 _TypeSafeStreamTransformer(this._inner);
27
28 Stream<T> bind(Stream<S> stream) =>
29 DelegatingStream.typed(_inner.bind(stream));
30 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698