| 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 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) { |
| 18 return IterableMixinWorkaround.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) => IterableMixinWorkaround.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)) => IterableMixinWorkaround.forEach(this, f); | 27 void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f); |
| 28 | 28 |
| 29 String join([String separator]) => IterableMixinWorkaround.joinList(this, sepa
rator); | 29 String join([String separator]) => |
| 30 IterableMixinWorkaround.joinList(this, separator); |
| 30 | 31 |
| 31 List mappedBy(f($E element)) => IterableMixinWorkaround.mappedByList(this, f); | 32 List mappedBy(f($E element)) => IterableMixinWorkaround.mappedByList(this, f); |
| 32 | 33 |
| 33 Iterable<$E> where(bool f($E element)) => IterableMixinWorkaround.where(this,
f); | 34 Iterable<$E> where(bool f($E element)) => |
| 35 IterableMixinWorkaround.where(this, f); |
| 34 | 36 |
| 35 bool every(bool f($E element)) => IterableMixinWorkaround.every(this, f); | 37 bool every(bool f($E element)) => IterableMixinWorkaround.every(this, f); |
| 36 | 38 |
| 37 bool any(bool f($E element)) => IterableMixinWorkaround.any(this, f); | 39 bool any(bool f($E element)) => IterableMixinWorkaround.any(this, f); |
| 38 | 40 |
| 39 List<$E> toList() => new List<$E>.from(this); | 41 List<$E> toList() => new List<$E>.from(this); |
| 40 Set<$E> toSet() => new Set<$E>.from(this); | 42 Set<$E> toSet() => new Set<$E>.from(this); |
| 41 | 43 |
| 42 bool get isEmpty => this.length == 0; | 44 bool get isEmpty => this.length == 0; |
| 43 | 45 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 $endif | 93 $endif |
| 92 | 94 |
| 93 $if DEFINE_CLEAR | 95 $if DEFINE_CLEAR |
| 94 void clear() { | 96 void clear() { |
| 95 throw new UnsupportedError("Cannot clear immutable List."); | 97 throw new UnsupportedError("Cannot clear immutable List."); |
| 96 } | 98 } |
| 97 $else | 99 $else |
| 98 // clear() defined by IDL. | 100 // clear() defined by IDL. |
| 99 $endif | 101 $endif |
| 100 | 102 |
| 103 List<$E> get reversed => |
| 104 new ReversedListView<$E>(this, 0, null); |
| 105 |
| 101 void sort([int compare($E a, $E b)]) { | 106 void sort([int compare($E a, $E b)]) { |
| 102 throw new UnsupportedError("Cannot sort immutable List."); | 107 throw new UnsupportedError("Cannot sort immutable List."); |
| 103 } | 108 } |
| 104 | 109 |
| 105 int indexOf($E element, [int start = 0]) => | 110 int indexOf($E element, [int start = 0]) => |
| 106 Lists.indexOf(this, element, start, this.length); | 111 Lists.indexOf(this, element, start, this.length); |
| 107 | 112 |
| 108 int lastIndexOf($E element, [int start]) { | 113 int lastIndexOf($E element, [int start]) { |
| 109 if (start == null) start = length - 1; | 114 if (start == null) start = length - 1; |
| 110 return Lists.lastIndexOf(this, element, start); | 115 return Lists.lastIndexOf(this, element, start); |
| 111 } | 116 } |
| 112 | 117 |
| 113 $E get first { | 118 $E get first { |
| 114 if (this.length > 0) return this[0]; | 119 if (this.length > 0) return this[0]; |
| 115 throw new StateError("No elements"); | 120 throw new StateError("No elements"); |
| 116 } | 121 } |
| 117 | 122 |
| 118 $E get last { | 123 $E get last { |
| 119 if (this.length > 0) return this[this.length - 1]; | 124 if (this.length > 0) return this[this.length - 1]; |
| 120 throw new StateError("No elements"); | 125 throw new StateError("No elements"); |
| 121 } | 126 } |
| 122 | 127 |
| 123 $E get single { | 128 $E get single { |
| 124 if (length == 1) return this[0]; | 129 if (length == 1) return this[0]; |
| 125 if (length == 0) throw new StateError("No elements"); | 130 if (length == 0) throw new StateError("No elements"); |
| 126 throw new StateError("More than one element"); | 131 throw new StateError("More than one element"); |
| 127 } | 132 } |
| 128 | 133 |
| 129 $E min([int compare($E a, $E b)]) => IterableMixinWorkaround.min(this, compare
); | 134 $E min([int compare($E a, $E b)]) => |
| 135 IterableMixinWorkaround.min(this, compare); |
| 130 | 136 |
| 131 $E max([int compare($E a, $E b)]) => IterableMixinWorkaround.max(this, compare
); | 137 $E max([int compare($E a, $E b)]) => |
| 138 IterableMixinWorkaround.max(this, compare); |
| 132 | 139 |
| 133 $E removeAt(int pos) { | 140 $E removeAt(int pos) { |
| 134 throw new UnsupportedError("Cannot remove from immutable List."); | 141 throw new UnsupportedError("Cannot remove from immutable List."); |
| 135 } | 142 } |
| 136 | 143 |
| 137 $E removeLast() { | 144 $E removeLast() { |
| 138 throw new UnsupportedError("Cannot remove from immutable List."); | 145 throw new UnsupportedError("Cannot remove from immutable List."); |
| 139 } | 146 } |
| 140 | 147 |
| 141 void remove(Object object) { | 148 void remove(Object object) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 167 } | 174 } |
| 168 | 175 |
| 169 void insertRange(int start, int rangeLength, [$E initialValue]) { | 176 void insertRange(int start, int rangeLength, [$E initialValue]) { |
| 170 throw new UnsupportedError("Cannot insertRange on immutable List."); | 177 throw new UnsupportedError("Cannot insertRange on immutable List."); |
| 171 } | 178 } |
| 172 | 179 |
| 173 List<$E> getRange(int start, int rangeLength) => | 180 List<$E> getRange(int start, int rangeLength) => |
| 174 Lists.getRange(this, start, rangeLength, <$E>[]); | 181 Lists.getRange(this, start, rangeLength, <$E>[]); |
| 175 | 182 |
| 176 // -- end List<$E> mixins. | 183 // -- end List<$E> mixins. |
| OLD | NEW |