Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 subscribe( | 262 subscribe( |
| 263 onData: (_) { count++; }, | 263 onData: (_) { count++; }, |
| 264 onError: future._setError, | 264 onError: future._setError, |
| 265 onDone: () { | 265 onDone: () { |
| 266 future._setValue(count); | 266 future._setValue(count); |
| 267 }, | 267 }, |
| 268 unsubscribeOnError: true); | 268 unsubscribeOnError: true); |
| 269 return future; | 269 return future; |
| 270 } | 270 } |
| 271 | 271 |
| 272 /** | |
| 273 * Finds the least element in the stream. | |
| 274 * | |
| 275 * If the stream is emtpy, the result is [:null:]. | |
|
Anders Johnsen
2013/01/02 11:04:05
empty
Lasse Reichstein Nielsen
2013/01/02 11:49:33
Done.
| |
| 276 * Otherwise the result is an value from the stream that is not greater | |
|
Anders Johnsen
2013/01/02 11:04:05
a value
Lasse Reichstein Nielsen
2013/01/02 11:49:33
Done.
| |
| 277 * than any other value from the stream (according to [compare], which must | |
| 278 * be a [Comparator]). | |
| 279 * | |
| 280 * If [compare] is omitted, it defaults to [Comparable.compare]. | |
| 281 */ | |
| 282 Future<T> min([int compare(T a, T b)]) { | |
| 283 _FutureImpl<T> future = new _FutureImpl<T>(); | |
| 284 StreamSubscription subscription; | |
| 285 T min = null; | |
| 286 subscription = subscribe( | |
| 287 onData: (T value) { | |
| 288 min = value; | |
| 289 subscription.onData = (T value) { | |
| 290 if (compare(min, value) > 0) min = value; | |
| 291 }; | |
| 292 }, | |
| 293 onError: future.setError, | |
| 294 onDone: () { | |
|
Anders Johnsen
2013/01/02 11:04:05
Is it an error if there ain't any elements?
Lasse Reichstein Nielsen
2013/01/02 11:49:33
No, min returns null in that case, also in Iterabl
| |
| 295 future._setValue(min); | |
| 296 }, | |
| 297 unsubscribeOnError: true | |
| 298 ); | |
| 299 } | |
| 300 | |
| 301 /** | |
| 302 * Finds the least element in the stream. | |
|
Anders Johnsen
2013/01/02 11:04:05
Update comment, largest element.
Lasse Reichstein Nielsen
2013/01/02 11:49:33
Done.
| |
| 303 * | |
| 304 * If the stream is emtpy, the result is [:null:]. | |
|
Anders Johnsen
2013/01/02 11:04:05
Ditto
Lasse Reichstein Nielsen
2013/01/02 11:49:33
Done.
| |
| 305 * Otherwise the result is an value from the stream that is not greater | |
| 306 * than any other value from the stream (according to [compare], which must | |
| 307 * be a [Comparator]). | |
| 308 * | |
| 309 * If [compare] is omitted, it defaults to [Comparable.compare]. | |
| 310 */ | |
| 311 Future<T> max([int compare(T a, T b)]) { | |
| 312 _FutureImpl<T> future = new _FutureImpl<T>(); | |
| 313 StreamSubscription subscription; | |
| 314 T max = null; | |
| 315 subscription = subscribe( | |
| 316 onData: (T value) { | |
| 317 max = value; | |
| 318 subscription.onData = (T value) { | |
| 319 if (compare(max, value) < 0) max = value; | |
| 320 }; | |
| 321 }, | |
| 322 onError: future.setError, | |
| 323 onDone: () { | |
| 324 future._setValue(max); | |
| 325 }, | |
| 326 unsubscribeOnError: true | |
| 327 ); | |
| 328 } | |
| 329 | |
| 272 /** Reports whether this stream contains any elements. */ | 330 /** Reports whether this stream contains any elements. */ |
| 273 Future<bool> get isEmpty { | 331 Future<bool> get isEmpty { |
| 274 _FutureImpl<bool> future = new _FutureImpl<bool>(); | 332 _FutureImpl<bool> future = new _FutureImpl<bool>(); |
| 275 StreamSubscription subscription; | 333 StreamSubscription subscription; |
| 276 subscription = subscribe( | 334 subscription = subscribe( |
| 277 onData: (_) { | 335 onData: (_) { |
| 278 subscription.unsubscribe(); | 336 subscription.unsubscribe(); |
| 279 future._setValue(false); | 337 future._setValue(false); |
| 280 }, | 338 }, |
| 281 onError: future._setError, | 339 onError: future._setError, |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 sink.signalError(error); | 841 sink.signalError(error); |
| 784 } | 842 } |
| 785 | 843 |
| 786 /** | 844 /** |
| 787 * Handle an incoming done event. | 845 * Handle an incoming done event. |
| 788 */ | 846 */ |
| 789 void handleDone(StreamSink<T> sink) { | 847 void handleDone(StreamSink<T> sink) { |
| 790 sink.close(); | 848 sink.close(); |
| 791 } | 849 } |
| 792 } | 850 } |
| OLD | NEW |