Chromium Code Reviews| Index: sdk/lib/async/stream.dart |
| diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart |
| index dd1acfd053880108150627608e11c26e5feca88e..ac9aa44f57100d188513095e9d91567aaa58f2cc 100644 |
| --- a/sdk/lib/async/stream.dart |
| +++ b/sdk/lib/async/stream.dart |
| @@ -269,6 +269,64 @@ abstract class Stream<T> { |
| return future; |
| } |
| + /** |
| + * Finds the least element in the stream. |
| + * |
| + * If the stream is empty, the result is [:null:]. |
| + * Otherwise the result is a value from the stream that is not greater |
| + * than any other value from the stream (according to [compare], which must |
| + * be a [Comparator]). |
| + * |
| + * If [compare] is omitted, it defaults to [Comparable.compare]. |
| + */ |
| + Future<T> min([int compare(T a, T b)]) { |
| + _FutureImpl<T> future = new _FutureImpl<T>(); |
| + StreamSubscription subscription; |
| + T min = null; |
| + subscription = subscribe( |
| + onData: (T value) { |
| + min = value; |
| + subscription.onData = (T value) { |
| + if (compare(min, value) > 0) min = value; |
| + }; |
| + }, |
| + onError: future.setError, |
| + onDone: () { |
| + future._setValue(min); |
| + }, |
| + unsubscribeOnError: true |
| + ); |
| + } |
| + |
| + /** |
| + * Finds the least element in the stream. |
| + * |
| + * If the stream is emtpy, the result is [:null:]. |
| + * Otherwise the result is an value from the stream that is not greater |
|
Sean Eagan
2013/01/02 16:35:13
greater -> less ?
|
| + * than any other value from the stream (according to [compare], which must |
| + * be a [Comparator]). |
| + * |
| + * If [compare] is omitted, it defaults to [Comparable.compare]. |
| + */ |
| + Future<T> max([int compare(T a, T b)]) { |
| + _FutureImpl<T> future = new _FutureImpl<T>(); |
| + StreamSubscription subscription; |
| + T max = null; |
| + subscription = subscribe( |
| + onData: (T value) { |
| + max = value; |
| + subscription.onData = (T value) { |
| + if (compare(max, value) < 0) max = value; |
| + }; |
| + }, |
| + onError: future.setError, |
| + onDone: () { |
| + future._setValue(max); |
| + }, |
| + unsubscribeOnError: true |
| + ); |
| + } |
| + |
| /** Reports whether this stream contains any elements. */ |
| Future<bool> get isEmpty { |
| _FutureImpl<bool> future = new _FutureImpl<bool>(); |