OLD | NEW |
---|---|
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:collection/collection.dart'; | 7 import 'package:collection/collection.dart'; |
8 | 8 |
9 import '../utils.dart'; | 9 import '../utils.dart'; |
10 import 'stream_subscription.dart'; | 10 import 'stream_subscription.dart'; |
11 import '../delegate/event_sink.dart'; | 11 import '../delegate/event_sink.dart'; |
12 | 12 |
13 class TypeSafeStream<T> implements Stream<T> { | 13 class TypeSafeStream<T> extends Stream<T> { |
floitsch
2017/05/16 09:01:18
should we add `groupBy` as an optimization?
| |
14 final Stream _stream; | 14 final Stream _stream; |
15 | 15 |
16 Future<T> get first async => (await _stream.first) as T; | 16 Future<T> get first async => (await _stream.first) as T; |
17 Future<T> get last async => (await _stream.last) as T; | 17 Future<T> get last async => (await _stream.last) as T; |
18 Future<T> get single async => (await _stream.single) as T; | 18 Future<T> get single async => (await _stream.single) as T; |
19 | 19 |
20 bool get isBroadcast => _stream.isBroadcast; | 20 bool get isBroadcast => _stream.isBroadcast; |
21 Future<bool> get isEmpty => _stream.isEmpty; | 21 Future<bool> get isEmpty => _stream.isEmpty; |
22 Future<int> get length => _stream.length; | 22 Future<int> get length => _stream.length; |
23 | 23 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 Future<T> elementAt(int index) async => (await _stream.elementAt(index)) as T; | 122 Future<T> elementAt(int index) async => (await _stream.elementAt(index)) as T; |
123 Future<bool> contains(Object needle) => _stream.contains(needle); | 123 Future<bool> contains(Object needle) => _stream.contains(needle); |
124 Future<String> join([String separator = ""]) => _stream.join(separator); | 124 Future<String> join([String separator = ""]) => _stream.join(separator); |
125 String toString() => _stream.toString(); | 125 String toString() => _stream.toString(); |
126 | 126 |
127 /// Returns a version of [function] that asserts that its argument is an | 127 /// Returns a version of [function] that asserts that its argument is an |
128 /// instance of `T`. | 128 /// instance of `T`. |
129 UnaryFunction<dynamic, S> _validateType<S>(S function(T value)) => | 129 UnaryFunction<dynamic, S> _validateType<S>(S function(T value)) => |
130 function == null ? null : (value) => function(value as T); | 130 function == null ? null : (value) => function(value as T); |
131 } | 131 } |
OLD | NEW |