Line data Source code
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 : /// Creates a wrapper that coerces the type of [transformer]. 8 : /// 9 : /// This soundly converts a [StreamTransformer] to a `StreamTransformer<S, T>`, 10 : /// regardless of its original generic type, by asserting that the events 11 : /// emitted by the transformed stream are instances of `T` whenever they're 12 : /// provided. If they're not, the stream throws a [TypeError]. 13 0 : @Deprecated('Use Stream.cast after binding a transformer instead') 14 : StreamTransformer<S, T> typedStreamTransformer<S, T>( 15 : StreamTransformer transformer) => 16 0 : transformer is StreamTransformer<S, T> 17 : ? transformer 18 0 : : _TypeSafeStreamTransformer(transformer); 19 : 20 : /// A wrapper that coerces the type of the stream returned by an inner 21 : /// transformer. 22 : class _TypeSafeStreamTransformer<S, T> extends StreamTransformerBase<S, T> { 23 : final StreamTransformer _inner; 24 : 25 0 : _TypeSafeStreamTransformer(this._inner); 26 : 27 0 : @override 28 0 : Stream<T> bind(Stream<S> stream) => _inner.bind(stream).cast(); 29 : }