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

Side by Side Diff: sdk/lib/core/iterable.dart

Issue 12188011: Added expand method to iterables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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/collection_dev/iterable.dart ('k') | sdk/lib/html/dart2js/html_dart2js.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * The [Iterable] interface allows to get an [Iterator] out of an 8 * The [Iterable] interface allows to get an [Iterator] out of an
9 * [Iterable] object. 9 * [Iterable] object.
10 * 10 *
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f); 51 Iterable map(f(E element)) => new MappedIterable<E, dynamic>(this, f);
52 52
53 /** 53 /**
54 * Deprecated alias for [map]. 54 * Deprecated alias for [map].
55 * 55 *
56 * @deprecated 56 * @deprecated
57 */ 57 */
58 Iterable mappedBy(f(E element)) => map(f); 58 Iterable mappedBy(f(E element)) => map(f);
59 59
60 /** 60 /**
61 * Returns a lazy [Iterable] with all elements that satisfy the 61 * Returns a lazy [Iterable] with all elements that satisfy the
62 * predicate [f]. 62 * predicate [f].
63 * 63 *
64 * This method returns a view of the mapped elements. As long as the 64 * This method returns a view of the mapped elements. As long as the
65 * returned [Iterable] is not iterated over, the supplied function [f] will 65 * returned [Iterable] is not iterated over, the supplied function [f] will
66 * not be invoked. Iterating will not cache results, and thus iterating 66 * not be invoked. Iterating will not cache results, and thus iterating
67 * multiple times over the the returned [Iterable] will invoke the supplied 67 * multiple times over the the returned [Iterable] will invoke the supplied
68 * function [f] multiple times on the same element. 68 * function [f] multiple times on the same element.
69 */ 69 */
70 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 70 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
71 71
72
73 /**
74 * Expand each element of this [Iterable] into zero or more elements.
75 *
76 * The resulting Iterable will run through the elements returned
77 * by [f] for each element of this, in order.
78 *
79 * The returned [Iterable] is lazy, and will call [f] for each element
80 * of this every time it's iterated.
81 */
82 Iterable expand(Iterable f(E element)) =>
83 new ExpandIterable<E, dynamic>(this, f);
84
72 /** 85 /**
73 * Check whether the collection contains an element equal to [element]. 86 * Check whether the collection contains an element equal to [element].
74 */ 87 */
75 bool contains(E element) { 88 bool contains(E element) {
76 for (E e in this) { 89 for (E e in this) {
77 if (e == element) return true; 90 if (e == element) return true;
78 } 91 }
79 return false; 92 return false;
80 } 93 }
81 94
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 _index++; 426 _index++;
414 return true; 427 return true;
415 } else { 428 } else {
416 _current = null; 429 _current = null;
417 return false; 430 return false;
418 } 431 }
419 } 432 }
420 433
421 E get current => _current; 434 E get current => _current;
422 } 435 }
OLDNEW
« no previous file with comments | « sdk/lib/collection_dev/iterable.dart ('k') | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698