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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « lib/src/transformer/typed.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:async/async.dart'; 7 import 'package:async/async.dart';
8 8
9 import 'src/guarantee_channel.dart'; 9 import 'src/guarantee_channel.dart';
10 import 'src/stream_channel_transformer.dart'; 10 import 'src/stream_channel_transformer.dart';
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 /// Transforms only the [sink] component of [this] using [transformer]. 102 /// Transforms only the [sink] component of [this] using [transformer].
103 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer); 103 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer);
104 104
105 /// Returns a copy of [this] with [stream] replaced by [change]'s return 105 /// Returns a copy of [this] with [stream] replaced by [change]'s return
106 /// value. 106 /// value.
107 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)); 107 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream));
108 108
109 /// Returns a copy of [this] with [sink] replaced by [change]'s return 109 /// Returns a copy of [this] with [sink] replaced by [change]'s return
110 /// value. 110 /// value.
111 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)); 111 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink));
112
113 /// Returns a copy of [this] with the generic type coerced to [S].
114 ///
115 /// If any events emitted by [stream] aren't of type [S], they're converted
116 /// into [CastError] events. Similarly, if any events are added to [sync] that
117 /// aren't of type [S], a [CastError] is thrown.
118 StreamChannel/*<S>*/ cast/*<S>*/();
112 } 119 }
113 120
114 /// An implementation of [StreamChannel] that simply takes a stream and a sink 121 /// An implementation of [StreamChannel] that simply takes a stream and a sink
115 /// as parameters. 122 /// as parameters.
116 /// 123 ///
117 /// This is distinct from [StreamChannel] so that it can use 124 /// This is distinct from [StreamChannel] so that it can use
118 /// [StreamChannelMixin]. 125 /// [StreamChannelMixin].
119 class _StreamChannel<T> extends StreamChannelMixin<T> { 126 class _StreamChannel<T> extends StreamChannelMixin<T> {
120 final Stream<T> stream; 127 final Stream<T> stream;
121 final StreamSink<T> sink; 128 final StreamSink<T> sink;
(...skipping 16 matching lines...) Expand all
138 changeStream(transformer.bind); 145 changeStream(transformer.bind);
139 146
140 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) => 147 StreamChannel<T> transformSink(StreamSinkTransformer<T, T> transformer) =>
141 changeSink(transformer.bind); 148 changeSink(transformer.bind);
142 149
143 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) => 150 StreamChannel<T> changeStream(Stream<T> change(Stream<T> stream)) =>
144 new StreamChannel(change(stream), sink); 151 new StreamChannel(change(stream), sink);
145 152
146 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) => 153 StreamChannel<T> changeSink(StreamSink<T> change(StreamSink<T> sink)) =>
147 new StreamChannel(stream, change(sink)); 154 new StreamChannel(stream, change(sink));
155
156 StreamChannel/*<S>*/ cast/*<S>*/() => new StreamChannel(
157 DelegatingStream.typed(stream), DelegatingStreamSink.typed(sink));
148 } 158 }
OLDNEW
« 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