| OLD | NEW |
| 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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 512 } |
| 513 | 513 |
| 514 /** | 514 /** |
| 515 * Forwards data events while [test] is successful. | 515 * Forwards data events while [test] is successful. |
| 516 * | 516 * |
| 517 * The returned stream provides the same events as this stream as long | 517 * The returned stream provides the same events as this stream as long |
| 518 * as [test] returns [:true:] for the event data. The stream is done | 518 * as [test] returns [:true:] for the event data. The stream is done |
| 519 * when either this stream is done, or when this stream first provides | 519 * when either this stream is done, or when this stream first provides |
| 520 * a value that [test] doesn't accept. | 520 * a value that [test] doesn't accept. |
| 521 */ | 521 */ |
| 522 Stream<T> takeWhile(bool test(T value)) { | 522 Stream<T> takeWhile(bool test(T element)) { |
| 523 return new _TakeWhileStream(this, test); | 523 return new _TakeWhileStream(this, test); |
| 524 } | 524 } |
| 525 | 525 |
| 526 /** | 526 /** |
| 527 * Skips the first [count] data events from this stream. | 527 * Skips the first [count] data events from this stream. |
| 528 */ | 528 */ |
| 529 Stream<T> skip(int count) { | 529 Stream<T> skip(int count) { |
| 530 return new _SkipStream(this, count); | 530 return new _SkipStream(this, count); |
| 531 } | 531 } |
| 532 | 532 |
| 533 /** | 533 /** |
| 534 * Skip data events from this stream while they are matched by [test]. | 534 * Skip data events from this stream while they are matched by [test]. |
| 535 * | 535 * |
| 536 * Error and done events are provided by the returned stream unmodified. | 536 * Error and done events are provided by the returned stream unmodified. |
| 537 * | 537 * |
| 538 * Starting with the first data event where [test] returns true for the | 538 * Starting with the first data event where [test] returns true for the |
| 539 * event data, the returned stream will have the same events as this stream. | 539 * event data, the returned stream will have the same events as this stream. |
| 540 */ | 540 */ |
| 541 Stream<T> skipWhile(bool test(T value)) { | 541 Stream<T> skipWhile(bool test(T element)) { |
| 542 return new _SkipWhileStream(this, test); | 542 return new _SkipWhileStream(this, test); |
| 543 } | 543 } |
| 544 | 544 |
| 545 /** | 545 /** |
| 546 * Skips data events if they are equal to the previous data event. | 546 * Skips data events if they are equal to the previous data event. |
| 547 * | 547 * |
| 548 * The returned stream provides the same events as this stream, except | 548 * The returned stream provides the same events as this stream, except |
| 549 * that it never provides two consequtive data events that are equal. | 549 * that it never provides two consequtive data events that are equal. |
| 550 * | 550 * |
| 551 * Equality is determined by the provided [equals] method. If that is | 551 * Equality is determined by the provided [equals] method. If that is |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 * that [test] returns true for. | 652 * that [test] returns true for. |
| 653 * | 653 * |
| 654 * If no such element is found before this stream is done, and a | 654 * If no such element is found before this stream is done, and a |
| 655 * [defaultValue] function is provided, the result of calling [defaultValue] | 655 * [defaultValue] function is provided, the result of calling [defaultValue] |
| 656 * becomes the value of the future. | 656 * becomes the value of the future. |
| 657 * | 657 * |
| 658 * If an error occurs, or if this stream ends without finding a match and | 658 * If an error occurs, or if this stream ends without finding a match and |
| 659 * with no [defaultValue] function provided, the future will receive an | 659 * with no [defaultValue] function provided, the future will receive an |
| 660 * error. | 660 * error. |
| 661 */ | 661 */ |
| 662 Future<T> firstWhere(bool test(T value), {T defaultValue()}) { | 662 Future<T> firstWhere(bool test(T element), {T defaultValue()}) { |
| 663 _FutureImpl<T> future = new _FutureImpl<T>(); | 663 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 664 StreamSubscription subscription; | 664 StreamSubscription subscription; |
| 665 subscription = this.listen( | 665 subscription = this.listen( |
| 666 // TODO(ahe): Restore type when feature is implemented in dart2js | 666 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 667 // checked mode. http://dartbug.com/7733 | 667 // checked mode. http://dartbug.com/7733 |
| 668 (/*T*/ value) { | 668 (/*T*/ value) { |
| 669 _runUserCode( | 669 _runUserCode( |
| 670 () => test(value), | 670 () => test(value), |
| 671 (bool isMatch) { | 671 (bool isMatch) { |
| 672 if (isMatch) { | 672 if (isMatch) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 689 return future; | 689 return future; |
| 690 } | 690 } |
| 691 | 691 |
| 692 /** | 692 /** |
| 693 * Finds the last element in this stream matching [test]. | 693 * Finds the last element in this stream matching [test]. |
| 694 * | 694 * |
| 695 * As [firstWhere], except that the last matching element is found. | 695 * As [firstWhere], except that the last matching element is found. |
| 696 * That means that the result cannot be provided before this stream | 696 * That means that the result cannot be provided before this stream |
| 697 * is done. | 697 * is done. |
| 698 */ | 698 */ |
| 699 Future<T> lastWhere(bool test(T value), {T defaultValue()}) { | 699 Future<T> lastWhere(bool test(T element), {T defaultValue()}) { |
| 700 _FutureImpl<T> future = new _FutureImpl<T>(); | 700 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 701 T result = null; | 701 T result = null; |
| 702 bool foundResult = false; | 702 bool foundResult = false; |
| 703 StreamSubscription subscription; | 703 StreamSubscription subscription; |
| 704 subscription = this.listen( | 704 subscription = this.listen( |
| 705 // TODO(ahe): Restore type when feature is implemented in dart2js | 705 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 706 // checked mode. http://dartbug.com/7733 | 706 // checked mode. http://dartbug.com/7733 |
| 707 (/*T*/ value) { | 707 (/*T*/ value) { |
| 708 _runUserCode( | 708 _runUserCode( |
| 709 () => true == test(value), | 709 () => true == test(value), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 731 cancelOnError: true); | 731 cancelOnError: true); |
| 732 return future; | 732 return future; |
| 733 } | 733 } |
| 734 | 734 |
| 735 /** | 735 /** |
| 736 * Finds the single element in this stream matching [test]. | 736 * Finds the single element in this stream matching [test]. |
| 737 * | 737 * |
| 738 * Like [lastMatch], except that it is an error if more than one | 738 * Like [lastMatch], except that it is an error if more than one |
| 739 * matching element occurs in the stream. | 739 * matching element occurs in the stream. |
| 740 */ | 740 */ |
| 741 Future<T> singleWhere(bool test(T value)) { | 741 Future<T> singleWhere(bool test(T element)) { |
| 742 _FutureImpl<T> future = new _FutureImpl<T>(); | 742 _FutureImpl<T> future = new _FutureImpl<T>(); |
| 743 T result = null; | 743 T result = null; |
| 744 bool foundResult = false; | 744 bool foundResult = false; |
| 745 StreamSubscription subscription; | 745 StreamSubscription subscription; |
| 746 subscription = this.listen( | 746 subscription = this.listen( |
| 747 // TODO(ahe): Restore type when feature is implemented in dart2js | 747 // TODO(ahe): Restore type when feature is implemented in dart2js |
| 748 // checked mode. http://dartbug.com/7733 | 748 // checked mode. http://dartbug.com/7733 |
| 749 (/*T*/ value) { | 749 (/*T*/ value) { |
| 750 _runUserCode( | 750 _runUserCode( |
| 751 () => true == test(value), | 751 () => true == test(value), |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 class _EventOutputSinkWrapper<T> extends EventSink<T> { | 1214 class _EventOutputSinkWrapper<T> extends EventSink<T> { |
| 1215 _EventOutputSink _sink; | 1215 _EventOutputSink _sink; |
| 1216 _EventOutputSinkWrapper(this._sink); | 1216 _EventOutputSinkWrapper(this._sink); |
| 1217 | 1217 |
| 1218 void add(T data) { _sink._sendData(data); } | 1218 void add(T data) { _sink._sendData(data); } |
| 1219 void addError(error) { _sink._sendError(error); } | 1219 void addError(error) { _sink._sendError(error); } |
| 1220 void close() { _sink._sendDone(); } | 1220 void close() { _sink._sendDone(); } |
| 1221 } | 1221 } |
| OLD | NEW |