| // -- start List<$E> mixins. |
| // $E is the element type. |
| |
| // From Iterable<$E>: |
| |
| Iterator<$E> get iterator { |
| // Note: NodeLists are not fixed size. And most probably length shouldn't |
| // be cached in both iterator _and_ forEach method. For now caching it |
| // for consistency. |
| return new FixedSizeListIterator<$E>(this); |
| } |
| |
| $if DEFINE_LENGTH_AS_NUM_ITEMS |
| // SVG Collections expose numberOfItems rather than length. |
| int get length => numberOfItems; |
| $endif |
| dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) { |
| return IterableMixinWorkaround.reduce(this, initialValue, combine); |
| } |
| |
| $if DEFINE_CONTAINS |
| bool contains($E element) => IterableMixinWorkaround.contains(this, element); |
| $else |
| // contains() defined by IDL. |
| $endif |
| |
| void forEach(void f($E element)) => IterableMixinWorkaround.forEach(this, f); |
| |
| String join([String separator]) => |
| IterableMixinWorkaround.joinList(this, separator); |
| |
| Iterable map(f($E element)) => |
| IterableMixinWorkaround.map(this, f); |
| |
| List mappedBy(f($E element)) => |
| IterableMixinWorkaround.mappedByList(this, f); |
| |
| Iterable<$E> where(bool f($E element)) => |
| IterableMixinWorkaround.where(this, f); |
| |
| bool every(bool f($E element)) => IterableMixinWorkaround.every(this, f); |
| |
| bool any(bool f($E element)) => IterableMixinWorkaround.any(this, f); |
| |
| List<$E> toList() => new List<$E>.from(this); |
| Set<$E> toSet() => new Set<$E>.from(this); |
| |
| bool get isEmpty => this.length == 0; |
| |
| Iterable<$E> take(int n) => IterableMixinWorkaround.takeList(this, n); |
| |
| Iterable<$E> takeWhile(bool test($E value)) { |
| return IterableMixinWorkaround.takeWhile(this, test); |
| } |
| |
| Iterable<$E> skip(int n) => IterableMixinWorkaround.skipList(this, n); |
| |
| Iterable<$E> skipWhile(bool test($E value)) { |
| return IterableMixinWorkaround.skipWhile(this, test); |
| } |
| |
| $E firstMatching(bool test($E value), { $E orElse() }) { |
| return IterableMixinWorkaround.firstMatching(this, test, orElse); |
| } |
| |
| $E lastMatching(bool test($E value), {$E orElse()}) { |
| return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); |
| } |
| |
| $E singleMatching(bool test($E value)) { |
| return IterableMixinWorkaround.singleMatching(this, test); |
| } |
| |
| $E elementAt(int index) { |
| return this[index]; |
| } |
| |
| // From Collection<$E>: |
| |
| void add($E value) { |
| throw new UnsupportedError("Cannot add to immutable List."); |
| } |
| |
| void addLast($E value) { |
| throw new UnsupportedError("Cannot add to immutable List."); |
| } |
| |
| void addAll(Iterable<$E> iterable) { |
| throw new UnsupportedError("Cannot add to immutable List."); |
| } |
| |
| // From List<$E>: |
| $if DEFINE_LENGTH_SETTER |
| void set length(int value) { |
| throw new UnsupportedError("Cannot resize immutable List."); |
| } |
| $endif |
| |
| $if DEFINE_CLEAR |
| void clear() { |
| throw new UnsupportedError("Cannot clear immutable List."); |
| } |
| $else |
| // clear() defined by IDL. |
| $endif |
| |
| List<$E> get reversed { |
| return IterableMixinWorkaround.reversedList(this); |
| } |
| |
| void sort([int compare($E a, $E b)]) { |
| throw new UnsupportedError("Cannot sort immutable List."); |
| } |
| |
| int indexOf($E element, [int start = 0]) => |
| Lists.indexOf(this, element, start, this.length); |
| |
| int lastIndexOf($E element, [int start]) { |
| if (start == null) start = length - 1; |
| return Lists.lastIndexOf(this, element, start); |
| } |
| |
| $E get first { |
| if (this.length > 0) return this[0]; |
| throw new StateError("No elements"); |
| } |
| |
| $E get last { |
| if (this.length > 0) return this[this.length - 1]; |
| throw new StateError("No elements"); |
| } |
| |
| $E get single { |
| if (length == 1) return this[0]; |
| if (length == 0) throw new StateError("No elements"); |
| throw new StateError("More than one element"); |
| } |
| |
| $E min([int compare($E a, $E b)]) => |
| IterableMixinWorkaround.min(this, compare); |
| |
| $E max([int compare($E a, $E b)]) => |
| IterableMixinWorkaround.max(this, compare); |
| |
| $E removeAt(int pos) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| $E removeLast() { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void remove(Object object) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void removeAll(Iterable elements) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void retainAll(Iterable elements) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void removeMatching(bool test($E element)) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void retainMatching(bool test($E element)) { |
| throw new UnsupportedError("Cannot remove from immutable List."); |
| } |
| |
| void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) { |
| throw new UnsupportedError("Cannot setRange on immutable List."); |
| } |
| |
| void removeRange(int start, int rangeLength) { |
| throw new UnsupportedError("Cannot removeRange on immutable List."); |
| } |
| |
| void insertRange(int start, int rangeLength, [$E initialValue]) { |
| throw new UnsupportedError("Cannot insertRange on immutable List."); |
| } |
| |
| List<$E> getRange(int start, int rangeLength) => |
| Lists.getRange(this, start, rangeLength, <$E>[]); |
| |
| // -- end List<$E> mixins. |