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

Side by Side Diff: sdk/lib/async/stream.dart

Issue 2885993005: Fix Stream.distinct. (Closed)
Patch Set: Created 3 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 | « no previous file | sdk/lib/async/stream_pipe.dart » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.async; 5 part of dart.async;
6 6
7 // ------------------------------------------------------------------- 7 // -------------------------------------------------------------------
8 // Core Stream types 8 // Core Stream types
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 10
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 */ 1015 */
1016 Stream<T> skipWhile(bool test(T element)) { 1016 Stream<T> skipWhile(bool test(T element)) {
1017 return new _SkipWhileStream<T>(this, test); 1017 return new _SkipWhileStream<T>(this, test);
1018 } 1018 }
1019 1019
1020 /** 1020 /**
1021 * Skips data events if they are equal to the previous data event. 1021 * Skips data events if they are equal to the previous data event.
1022 * 1022 *
1023 * The returned stream provides the same events as this stream, except 1023 * The returned stream provides the same events as this stream, except
1024 * that it never provides two consecutive data events that are equal. 1024 * that it never provides two consecutive data events that are equal.
1025 * That is, errors are passed through to the returned stream, and
1026 * data events are passed through if they are distinct from the most
1027 * recently emitted data event.
1025 * 1028 *
1026 * Equality is determined by the provided [equals] method. If that is 1029 * Equality is determined by the provided [equals] method. If that is
1027 * omitted, the '==' operator on the last provided data element is used. 1030 * omitted, the '==' operator on the last provided data element is used.
1028 * 1031 *
1032 * If [equals] throws, the data event is replaced by an error event
1033 * containing the thrown error. The behavior is equivalent to the
1034 * original stream emitting the error event.
1035 *
1029 * The returned stream is a broadcast stream if this stream is. 1036 * The returned stream is a broadcast stream if this stream is.
1030 * If a broadcast stream is listened to more than once, each subscription 1037 * If a broadcast stream is listened to more than once, each subscription
1031 * will individually perform the `equals` test. 1038 * will individually perform the `equals` test.
1032 */ 1039 */
1033 Stream<T> distinct([bool equals(T previous, T next)]) { 1040 Stream<T> distinct([bool equals(T previous, T next)]) {
1034 return new _DistinctStream<T>(this, equals); 1041 return new _DistinctStream<T>(this, equals);
1035 } 1042 }
1036 1043
1037 /** 1044 /**
1038 * Returns the first element of the stream. 1045 * Returns the first element of the stream.
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 /// Must only be used instead of listening to the [values] stream. 1939 /// Must only be used instead of listening to the [values] stream.
1933 /// If the stream has been listened to, this call fails. 1940 /// If the stream has been listened to, this call fails.
1934 /// After calling this method, listening on the [values] stream fails. 1941 /// After calling this method, listening on the [values] stream fails.
1935 Future cancel() { 1942 Future cancel() {
1936 // If values has been listened to, 1943 // If values has been listened to,
1937 // this throws a StateError saying that stream has already been listened to, 1944 // this throws a StateError saying that stream has already been listened to,
1938 // which is a correct error message for this call too. 1945 // which is a correct error message for this call too.
1939 return values.listen(null).cancel(); 1946 return values.listen(null).cancel();
1940 } 1947 }
1941 } 1948 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/async/stream_pipe.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698