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

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

Issue 2529393002: Make core libraries use generic method syntax. (Closed)
Patch Set: Merge to head Created 4 years 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
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 * A collection of values, or "elements", that can be accessed sequentially. 8 * A collection of values, or "elements", that can be accessed sequentially.
9 * 9 *
10 * The elements of the iterable are accessed by getting an [Iterator] 10 * The elements of the iterable are accessed by getting an [Iterator]
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 * This method returns a view of the mapped elements. As long as the 147 * This method returns a view of the mapped elements. As long as the
148 * returned [Iterable] is not iterated over, the supplied function [f] will 148 * returned [Iterable] is not iterated over, the supplied function [f] will
149 * not be invoked. The transformed elements will not be cached. Iterating 149 * not be invoked. The transformed elements will not be cached. Iterating
150 * multiple times over the returned [Iterable] will invoke the supplied 150 * multiple times over the returned [Iterable] will invoke the supplied
151 * function [f] multiple times on the same element. 151 * function [f] multiple times on the same element.
152 * 152 *
153 * Methods on the returned iterable are allowed to omit calling `f` 153 * Methods on the returned iterable are allowed to omit calling `f`
154 * on any element where the result isn't needed. 154 * on any element where the result isn't needed.
155 * For example, [elementAt] may call `f` only once. 155 * For example, [elementAt] may call `f` only once.
156 */ 156 */
157 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E e)) => 157 Iterable<T> map<T>(T f(E e)) =>
158 new MappedIterable<E, dynamic/*=T*/>(this, f); 158 new MappedIterable<E, T>(this, f);
159 159
160 /** 160 /**
161 * Returns a new lazy [Iterable] with all elements that satisfy the 161 * Returns a new lazy [Iterable] with all elements that satisfy the
162 * predicate [test]. 162 * predicate [test].
163 * 163 *
164 * The matching elements have the same order in the returned iterable 164 * The matching elements have the same order in the returned iterable
165 * as they have in [iterator]. 165 * as they have in [iterator].
166 * 166 *
167 * This method returns a view of the mapped elements. 167 * This method returns a view of the mapped elements.
168 * As long as the returned [Iterable] is not iterated over, 168 * As long as the returned [Iterable] is not iterated over,
(...skipping 17 matching lines...) Expand all
186 * 186 *
187 * var pairs = [[1, 2], [3, 4]]; 187 * var pairs = [[1, 2], [3, 4]];
188 * var flattened = pairs.expand((pair) => pair).toList(); 188 * var flattened = pairs.expand((pair) => pair).toList();
189 * print(flattened); // => [1, 2, 3, 4]; 189 * print(flattened); // => [1, 2, 3, 4];
190 * 190 *
191 * var input = [1, 2, 3]; 191 * var input = [1, 2, 3];
192 * var duplicated = input.expand((i) => [i, i]).toList(); 192 * var duplicated = input.expand((i) => [i, i]).toList();
193 * print(duplicated); // => [1, 1, 2, 2, 3, 3] 193 * print(duplicated); // => [1, 1, 2, 2, 3, 3]
194 * 194 *
195 */ 195 */
196 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) => 196 Iterable<T> expand<T>(Iterable<T> f(E element)) =>
197 new ExpandIterable<E, dynamic/*=T*/>(this, f); 197 new ExpandIterable<E, T>(this, f);
198 198
199 /** 199 /**
200 * Returns true if the collection contains an element equal to [element]. 200 * Returns true if the collection contains an element equal to [element].
201 * 201 *
202 * This operation will check each element in order for being equal to 202 * This operation will check each element in order for being equal to
203 * [element], unless it has a more efficient way to find an element 203 * [element], unless it has a more efficient way to find an element
204 * equal to [element]. 204 * equal to [element].
205 * 205 *
206 * The equality used to determine whether [element] is equal to an element of 206 * The equality used to determine whether [element] is equal to an element of
207 * the iterable defaults to the [Object.==] of the element. 207 * the iterable defaults to the [Object.==] of the element.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 * for (E element in this) { 273 * for (E element in this) {
274 * value = combine(value, element); 274 * value = combine(value, element);
275 * } 275 * }
276 * return value; 276 * return value;
277 * 277 *
278 * Example of calculating the sum of an iterable: 278 * Example of calculating the sum of an iterable:
279 * 279 *
280 * iterable.fold(0, (prev, element) => prev + element); 280 * iterable.fold(0, (prev, element) => prev + element);
281 * 281 *
282 */ 282 */
283 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue, 283 T fold<T>(T initialValue,
floitsch 2016/12/13 12:42:25 one line?
Lasse Reichstein Nielsen 2016/12/13 14:28:03 Done.
284 dynamic/*=T*/ combine(var/*=T*/ previousValue, E element)) { 284 T combine(T previousValue, E element)) {
285 var value = initialValue; 285 var value = initialValue;
286 for (E element in this) value = combine(value, element); 286 for (E element in this) value = combine(value, element);
287 return value; 287 return value;
288 } 288 }
289 289
290 /** 290 /**
291 * Checks whether every element of this iterable satisfies [test]. 291 * Checks whether every element of this iterable satisfies [test].
292 * 292 *
293 * Checks every element in iteration order, and returns `false` if 293 * Checks every element in iteration order, and returns `false` if
294 * any of them make [test] return `false`, otherwise returns `true`. 294 * any of them make [test] return `false`, otherwise returns `true`.
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 */ 647 */
648 abstract class BidirectionalIterator<E> implements Iterator<E> { 648 abstract class BidirectionalIterator<E> implements Iterator<E> {
649 /** 649 /**
650 * Move back to the previous element. 650 * Move back to the previous element.
651 * 651 *
652 * Returns true and updates [current] if successful. Returns false 652 * Returns true and updates [current] if successful. Returns false
653 * and sets [current] to null if there is no previous element. 653 * and sets [current] to null if there is no previous element.
654 */ 654 */
655 bool movePrevious(); 655 bool movePrevious();
656 } 656 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698