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

Side by Side Diff: tools/dom/templates/immutable_list_mixin.darttemplate

Issue 11971016: Create IterableMixinWorkaround and move most of the Collections methods there. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo (mappedByList instead of mappedBy). Created 7 years, 11 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 | « tools/dom/templates/html/impl/impl_Node.darttemplate ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // -- start List<$E> mixins. 1 // -- start List<$E> mixins.
2 // $E is the element type. 2 // $E is the element type.
3 3
4 // From Iterable<$E>: 4 // From Iterable<$E>:
5 5
6 Iterator<$E> get iterator { 6 Iterator<$E> get iterator {
7 // Note: NodeLists are not fixed size. And most probably length shouldn't 7 // Note: NodeLists are not fixed size. And most probably length shouldn't
8 // be cached in both iterator _and_ forEach method. For now caching it 8 // be cached in both iterator _and_ forEach method. For now caching it
9 // for consistency. 9 // for consistency.
10 return new FixedSizeListIterator<$E>(this); 10 return new FixedSizeListIterator<$E>(this);
11 } 11 }
12 12
13 $if DEFINE_LENGTH_AS_NUM_ITEMS 13 $if DEFINE_LENGTH_AS_NUM_ITEMS
14 // SVG Collections expose numberOfItems rather than length. 14 // SVG Collections expose numberOfItems rather than length.
15 int get length => numberOfItems; 15 int get length => numberOfItems;
16 $endif 16 $endif
17 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) { 17 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) {
18 return Collections.reduce(this, initialValue, combine); 18 return IterableMixinWorkaround.reduce(this, initialValue, combine);
19 } 19 }
20 20
21 $if DEFINE_CONTAINS 21 $if DEFINE_CONTAINS
22 bool contains($E element) => Collections.contains(this, element); 22 bool contains($E element) => IterableMixinWorkaround.contains(this, element);
23 $else 23 $else
24 // contains() defined by IDL. 24 // contains() defined by IDL.
25 $endif 25 $endif
26 26
27 void forEach(void f($E element)) => Collections.forEach(this, f); 27 void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f);
28 28
29 String join([String separator]) => Collections.joinList(this, separator); 29 String join([String separator]) => IterableMixinWorkaround.joinList(this, sepa rator);
30 30
31 List mappedBy(f($E element)) => new MappedList<$E, dynamic>(this, f); 31 List mappedBy(f($E element)) => IterableMixinWorkaround.mappedByList(this, f);
32 32
33 Iterable<$E> where(bool f($E element)) => new WhereIterable<$E>(this, f); 33 Iterable<$E> where(bool f($E element)) => IterableMixinWorkaround.where(this, f);
34 34
35 bool every(bool f($E element)) => Collections.every(this, f); 35 bool every(bool f($E element)) => IterableMixinWorkaround.every(this, f);
36 36
37 bool any(bool f($E element)) => Collections.any(this, f); 37 bool any(bool f($E element)) => IterableMixinWorkaround.any(this, f);
38 38
39 List<$E> toList() => new List<$E>.from(this); 39 List<$E> toList() => new List<$E>.from(this);
40 Set<$E> toSet() => new Set<$E>.from(this); 40 Set<$E> toSet() => new Set<$E>.from(this);
41 41
42 bool get isEmpty => this.length == 0; 42 bool get isEmpty => this.length == 0;
43 43
44 List<$E> take(int n) => new ListView<$E>(this, 0, n); 44 List<$E> take(int n) => IterableMixinWorkaround.takeList(this, n);
45 45
46 Iterable<$E> takeWhile(bool test($E value)) { 46 Iterable<$E> takeWhile(bool test($E value)) {
47 return new TakeWhileIterable<$E>(this, test); 47 return IterableMixinWorkaround.takeWhile(this, test);
48 } 48 }
49 49
50 List<$E> skip(int n) => new ListView<$E>(this, n, null); 50 List<$E> skip(int n) => IterableMixinWorkaround.skipList(this, n);
51 51
52 Iterable<$E> skipWhile(bool test($E value)) { 52 Iterable<$E> skipWhile(bool test($E value)) {
53 return new SkipWhileIterable<$E>(this, test); 53 return IterableMixinWorkaround.skipWhile(this, test);
54 } 54 }
55 55
56 $E firstMatching(bool test($E value), { $E orElse() }) { 56 $E firstMatching(bool test($E value), { $E orElse() }) {
57 return Collections.firstMatching(this, test, orElse); 57 return IterableMixinWorkaround.firstMatching(this, test, orElse);
58 } 58 }
59 59
60 $E lastMatching(bool test($E value), {$E orElse()}) { 60 $E lastMatching(bool test($E value), {$E orElse()}) {
61 return Collections.lastMatchingInList(this, test, orElse); 61 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse);
62 } 62 }
63 63
64 $E singleMatching(bool test($E value)) { 64 $E singleMatching(bool test($E value)) {
65 return Collections.singleMatching(this, test); 65 return IterableMixinWorkaround.singleMatching(this, test);
66 } 66 }
67 67
68 $E elementAt(int index) { 68 $E elementAt(int index) {
69 return this[index]; 69 return this[index];
70 } 70 }
71 71
72 // From Collection<$E>: 72 // From Collection<$E>:
73 73
74 void add($E value) { 74 void add($E value) {
75 throw new UnsupportedError("Cannot add to immutable List."); 75 throw new UnsupportedError("Cannot add to immutable List.");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 if (this.length > 0) return this[this.length - 1]; 119 if (this.length > 0) return this[this.length - 1];
120 throw new StateError("No elements"); 120 throw new StateError("No elements");
121 } 121 }
122 122
123 $E get single { 123 $E get single {
124 if (length == 1) return this[0]; 124 if (length == 1) return this[0];
125 if (length == 0) throw new StateError("No elements"); 125 if (length == 0) throw new StateError("No elements");
126 throw new StateError("More than one element"); 126 throw new StateError("More than one element");
127 } 127 }
128 128
129 $E min([int compare($E a, $E b)]) => Collections.min(this, compare); 129 $E min([int compare($E a, $E b)]) => IterableMixinWorkaround.min(this, compare );
130 130
131 $E max([int compare($E a, $E b)]) => Collections.max(this, compare); 131 $E max([int compare($E a, $E b)]) => IterableMixinWorkaround.max(this, compare );
132 132
133 $E removeAt(int pos) { 133 $E removeAt(int pos) {
134 throw new UnsupportedError("Cannot removeAt on immutable List."); 134 throw new UnsupportedError("Cannot removeAt on immutable List.");
135 } 135 }
136 136
137 $E removeLast() { 137 $E removeLast() {
138 throw new UnsupportedError("Cannot removeLast on immutable List."); 138 throw new UnsupportedError("Cannot removeLast on immutable List.");
139 } 139 }
140 140
141 void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) { 141 void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) {
142 throw new UnsupportedError("Cannot setRange on immutable List."); 142 throw new UnsupportedError("Cannot setRange on immutable List.");
143 } 143 }
144 144
145 void removeRange(int start, int rangeLength) { 145 void removeRange(int start, int rangeLength) {
146 throw new UnsupportedError("Cannot removeRange on immutable List."); 146 throw new UnsupportedError("Cannot removeRange on immutable List.");
147 } 147 }
148 148
149 void insertRange(int start, int rangeLength, [$E initialValue]) { 149 void insertRange(int start, int rangeLength, [$E initialValue]) {
150 throw new UnsupportedError("Cannot insertRange on immutable List."); 150 throw new UnsupportedError("Cannot insertRange on immutable List.");
151 } 151 }
152 152
153 List<$E> getRange(int start, int rangeLength) => 153 List<$E> getRange(int start, int rangeLength) =>
154 Lists.getRange(this, start, rangeLength, <$E>[]); 154 Lists.getRange(this, start, rangeLength, <$E>[]);
155 155
156 // -- end List<$E> mixins. 156 // -- end List<$E> mixins.
OLDNEW
« no previous file with comments | « tools/dom/templates/html/impl/impl_Node.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698