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

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

Issue 14246008: Allow Object when doing lookups. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot to upload before committing Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/lib/js_array.dart ('k') | sdk/lib/collection/hash_map.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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 result._setError(e); 305 result._setError(e);
306 }, 306 },
307 onDone: () { 307 onDone: () {
308 result._setValue(value); 308 result._setValue(value);
309 }, 309 },
310 cancelOnError: true); 310 cancelOnError: true);
311 return result; 311 return result;
312 } 312 }
313 313
314 /** 314 /**
315 * Checks whether [match] occurs in the elements provided by this stream. 315 * Checks whether [needle] occurs in the elements provided by this stream.
316 * 316 *
317 * Completes the [Future] when the answer is known. 317 * Completes the [Future] when the answer is known.
318 * If this stream reports an error, the [Future] will report that error. 318 * If this stream reports an error, the [Future] will report that error.
319 */ 319 */
320 Future<bool> contains(T match) { 320 Future<bool> contains(Object needle) {
321 _FutureImpl<bool> future = new _FutureImpl<bool>(); 321 _FutureImpl<bool> future = new _FutureImpl<bool>();
322 StreamSubscription subscription; 322 StreamSubscription subscription;
323 subscription = this.listen( 323 subscription = this.listen(
324 // TODO(ahe): Restore type when feature is implemented in dart2js 324 // TODO(ahe): Restore type when feature is implemented in dart2js
325 // checked mode. http://dartbug.com/7733 325 // checked mode. http://dartbug.com/7733
326 (/*T*/ element) { 326 (/*T*/ element) {
327 _runUserCode( 327 _runUserCode(
328 () => (element == match), 328 () => (element == needle),
329 (bool isMatch) { 329 (bool isMatch) {
330 if (isMatch) { 330 if (isMatch) {
331 subscription.cancel(); 331 subscription.cancel();
332 future._setValue(true); 332 future._setValue(true);
333 } 333 }
334 }, 334 },
335 _cancelAndError(subscription, future) 335 _cancelAndError(subscription, future)
336 ); 336 );
337 }, 337 },
338 onError: future._setError, 338 onError: future._setError,
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 * that [test] returns true for. 671 * that [test] returns true for.
672 * 672 *
673 * If no such element is found before this stream is done, and a 673 * If no such element is found before this stream is done, and a
674 * [defaultValue] function is provided, the result of calling [defaultValue] 674 * [defaultValue] function is provided, the result of calling [defaultValue]
675 * becomes the value of the future. 675 * becomes the value of the future.
676 * 676 *
677 * If an error occurs, or if this stream ends without finding a match and 677 * If an error occurs, or if this stream ends without finding a match and
678 * with no [defaultValue] function provided, the future will receive an 678 * with no [defaultValue] function provided, the future will receive an
679 * error. 679 * error.
680 */ 680 */
681 Future<T> firstWhere(bool test(T element), {T defaultValue()}) { 681 Future<dynamic> firstWhere(bool test(T element), {Object defaultValue()}) {
682 _FutureImpl<T> future = new _FutureImpl<T>(); 682 _FutureImpl<dynamic> future = new _FutureImpl();
683 StreamSubscription subscription; 683 StreamSubscription subscription;
684 subscription = this.listen( 684 subscription = this.listen(
685 // TODO(ahe): Restore type when feature is implemented in dart2js 685 // TODO(ahe): Restore type when feature is implemented in dart2js
686 // checked mode. http://dartbug.com/7733 686 // checked mode. http://dartbug.com/7733
687 (/*T*/ value) { 687 (/*T*/ value) {
688 _runUserCode( 688 _runUserCode(
689 () => test(value), 689 () => test(value),
690 (bool isMatch) { 690 (bool isMatch) {
691 if (isMatch) { 691 if (isMatch) {
692 subscription.cancel(); 692 subscription.cancel();
(...skipping 15 matching lines...) Expand all
708 return future; 708 return future;
709 } 709 }
710 710
711 /** 711 /**
712 * Finds the last element in this stream matching [test]. 712 * Finds the last element in this stream matching [test].
713 * 713 *
714 * As [firstWhere], except that the last matching element is found. 714 * As [firstWhere], except that the last matching element is found.
715 * That means that the result cannot be provided before this stream 715 * That means that the result cannot be provided before this stream
716 * is done. 716 * is done.
717 */ 717 */
718 Future<T> lastWhere(bool test(T element), {T defaultValue()}) { 718 Future<dynamic> lastWhere(bool test(T element), {Object defaultValue()}) {
719 _FutureImpl<T> future = new _FutureImpl<T>(); 719 _FutureImpl<dynamic> future = new _FutureImpl();
720 T result = null; 720 T result = null;
721 bool foundResult = false; 721 bool foundResult = false;
722 StreamSubscription subscription; 722 StreamSubscription subscription;
723 subscription = this.listen( 723 subscription = this.listen(
724 // TODO(ahe): Restore type when feature is implemented in dart2js 724 // TODO(ahe): Restore type when feature is implemented in dart2js
725 // checked mode. http://dartbug.com/7733 725 // checked mode. http://dartbug.com/7733
726 (/*T*/ value) { 726 (/*T*/ value) {
727 _runUserCode( 727 _runUserCode(
728 () => true == test(value), 728 () => true == test(value),
729 (bool isMatch) { 729 (bool isMatch) {
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 * 1246 *
1247 * If a [moveNext] call has been made, it will complete with `false` as value, 1247 * If a [moveNext] call has been made, it will complete with `false` as value,
1248 * as will all further calls to [moveNext]. 1248 * as will all further calls to [moveNext].
1249 * 1249 *
1250 * If you need to stop listening for values before the stream iterator is 1250 * If you need to stop listening for values before the stream iterator is
1251 * automatically closed, you must call [cancel] to ensure that the stream 1251 * automatically closed, you must call [cancel] to ensure that the stream
1252 * is properly closed. 1252 * is properly closed.
1253 */ 1253 */
1254 void cancel(); 1254 void cancel();
1255 } 1255 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/lib/js_array.dart ('k') | sdk/lib/collection/hash_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698