OLD | NEW |
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 $E reduce($E combine($E value, $E element)) { |
18 return IterableMixinWorkaround.reduce(this, initialValue, combine); | 18 return IterableMixinWorkaround.reduce(this, combine); |
19 } | 19 } |
20 | 20 |
21 dynamic fold(dynamic initialValue, dynamic combine(dynamic, $E)) { | 21 dynamic fold(dynamic initialValue, |
| 22 dynamic combine(dynamic previousValue, $E element)) { |
22 return IterableMixinWorkaround.fold(this, initialValue, combine); | 23 return IterableMixinWorkaround.fold(this, initialValue, combine); |
23 } | 24 } |
24 | 25 |
25 $if DEFINE_CONTAINS | 26 $if DEFINE_CONTAINS |
26 bool contains($E element) => IterableMixinWorkaround.contains(this, element); | 27 bool contains($E element) => IterableMixinWorkaround.contains(this, element); |
27 $else | 28 $else |
28 // contains() defined by IDL. | 29 // contains() defined by IDL. |
29 $endif | 30 $endif |
30 | 31 |
31 void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f); | 32 void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (this.length > 0) return this[this.length - 1]; | 132 if (this.length > 0) return this[this.length - 1]; |
132 throw new StateError("No elements"); | 133 throw new StateError("No elements"); |
133 } | 134 } |
134 | 135 |
135 $E get single { | 136 $E get single { |
136 if (length == 1) return this[0]; | 137 if (length == 1) return this[0]; |
137 if (length == 0) throw new StateError("No elements"); | 138 if (length == 0) throw new StateError("No elements"); |
138 throw new StateError("More than one element"); | 139 throw new StateError("More than one element"); |
139 } | 140 } |
140 | 141 |
141 $E min([int compare($E a, $E b)]) => | |
142 IterableMixinWorkaround.min(this, compare); | |
143 | |
144 $E max([int compare($E a, $E b)]) => | |
145 IterableMixinWorkaround.max(this, compare); | |
146 | |
147 void insert(int index, $E element) { | 142 void insert(int index, $E element) { |
148 throw new UnsupportedError("Cannot add to immutable List."); | 143 throw new UnsupportedError("Cannot add to immutable List."); |
149 } | 144 } |
150 | 145 |
151 $E removeAt(int pos) { | 146 $E removeAt(int pos) { |
152 throw new UnsupportedError("Cannot remove from immutable List."); | 147 throw new UnsupportedError("Cannot remove from immutable List."); |
153 } | 148 } |
154 | 149 |
155 $E removeLast() { | 150 $E removeLast() { |
156 throw new UnsupportedError("Cannot remove from immutable List."); | 151 throw new UnsupportedError("Cannot remove from immutable List."); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 IterableMixinWorkaround.asMapList(this); | 195 IterableMixinWorkaround.asMapList(this); |
201 | 196 |
202 String toString() { | 197 String toString() { |
203 StringBuffer buffer = new StringBuffer('['); | 198 StringBuffer buffer = new StringBuffer('['); |
204 buffer.writeAll(this, ', '); | 199 buffer.writeAll(this, ', '); |
205 buffer.write(']'); | 200 buffer.write(']'); |
206 return buffer.toString(); | 201 return buffer.toString(); |
207 } | 202 } |
208 | 203 |
209 // -- end List<$E> mixins. | 204 // -- end List<$E> mixins. |
OLD | NEW |