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

Side by Side Diff: sdk/lib/collection/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) 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.collection; 5 part of dart.collection;
6 6
7 /** 7 /**
8 * This [Iterable] mixin implements all [Iterable] members except `iterator`. 8 * This [Iterable] mixin implements all [Iterable] members except `iterator`.
9 * 9 *
10 * All other methods are implemented in terms of `iterator`. 10 * All other methods are implemented in terms of `iterator`.
11 */ 11 */
12 abstract class IterableMixin<E> implements Iterable<E> { 12 abstract class IterableMixin<E> implements Iterable<E> {
13 // This class has methods copied verbatim into: 13 // This class has methods copied verbatim into:
14 // - IterableBase 14 // - IterableBase
15 // - SetMixin 15 // - SetMixin
16 // If changing a method here, also change the other copies. 16 // If changing a method here, also change the other copies.
17 17
18 Iterable/*<T>*/ map/*<T>*/(/*=T*/ f(E element)) => 18 Iterable<T> map<T>(T f(E element)) =>
19 new MappedIterable<E, dynamic/*=T*/>(this, f); 19 new MappedIterable<E, T>(this, f);
20 20
21 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f); 21 Iterable<E> where(bool f(E element)) => new WhereIterable<E>(this, f);
22 22
23 Iterable/*<T>*/ expand/*<T>*/(Iterable/*<T>*/ f(E element)) => 23 Iterable<T> expand<T>(Iterable<T> f(E element)) =>
24 new ExpandIterable<E, dynamic/*=T*/>(this, f); 24 new ExpandIterable<E, T>(this, f);
25 25
26 bool contains(Object element) { 26 bool contains(Object element) {
27 for (E e in this) { 27 for (E e in this) {
28 if (e == element) return true; 28 if (e == element) return true;
29 } 29 }
30 return false; 30 return false;
31 } 31 }
32 32
33 void forEach(void f(E element)) { 33 void forEach(void f(E element)) {
34 for (E element in this) f(element); 34 for (E element in this) f(element);
35 } 35 }
36 36
37 E reduce(E combine(E value, E element)) { 37 E reduce(E combine(E value, E element)) {
38 Iterator<E> iterator = this.iterator; 38 Iterator<E> iterator = this.iterator;
39 if (!iterator.moveNext()) { 39 if (!iterator.moveNext()) {
40 throw IterableElementError.noElement(); 40 throw IterableElementError.noElement();
41 } 41 }
42 E value = iterator.current; 42 E value = iterator.current;
43 while (iterator.moveNext()) { 43 while (iterator.moveNext()) {
44 value = combine(value, iterator.current); 44 value = combine(value, iterator.current);
45 } 45 }
46 return value; 46 return value;
47 } 47 }
48 48
49 dynamic/*=T*/ fold/*<T>*/(var/*=T*/ initialValue, 49 T fold<T>(T initialValue,
floitsch 2016/12/13 12:42:24 Does this fit on one line?
Lasse Reichstein Nielsen 2016/12/13 14:28:03 Done.
50 dynamic/*=T*/ combine(var/*=T*/ previousValue, E element)) { 50 T combine(T previousValue, E element)) {
51 var value = initialValue; 51 var value = initialValue;
52 for (E element in this) value = combine(value, element); 52 for (E element in this) value = combine(value, element);
53 return value; 53 return value;
54 } 54 }
55 55
56 bool every(bool f(E element)) { 56 bool every(bool f(E element)) {
57 for (E element in this) { 57 for (E element in this) {
58 if (!f(element)) return false; 58 if (!f(element)) return false;
59 } 59 }
60 return true; 60 return true;
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 elision = "..."; 391 elision = "...";
392 length += ELLIPSIS_SIZE + OVERHEAD; 392 length += ELLIPSIS_SIZE + OVERHEAD;
393 } 393 }
394 } 394 }
395 if (elision != null) { 395 if (elision != null) {
396 parts.add(elision); 396 parts.add(elision);
397 } 397 }
398 parts.add(penultimateString); 398 parts.add(penultimateString);
399 parts.add(ultimateString); 399 parts.add(ultimateString);
400 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698