| OLD | NEW |
| (Empty) |
| 1 // -- start List<$E> mixins. | |
| 2 // $E is the element type. | |
| 3 | |
| 4 // From Iterable<$E>: | |
| 5 | |
| 6 Iterator<$E> iterator() { | |
| 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 | |
| 9 // for consistency. | |
| 10 return new FixedSizeListIterator<$E>(this); | |
| 11 } | |
| 12 | |
| 13 // From Collection<$E>: | |
| 14 $if DEFINE_LENGTH_AS_NUM_ITEMS | |
| 15 // SVG Collections expose numberOfItems rather than length. | |
| 16 int get length => numberOfItems; | |
| 17 $endif | |
| 18 | |
| 19 void add($E value) { | |
| 20 throw new UnsupportedError("Cannot add to immutable List."); | |
| 21 } | |
| 22 | |
| 23 void addLast($E value) { | |
| 24 throw new UnsupportedError("Cannot add to immutable List."); | |
| 25 } | |
| 26 | |
| 27 void addAll(Collection<$E> collection) { | |
| 28 throw new UnsupportedError("Cannot add to immutable List."); | |
| 29 } | |
| 30 | |
| 31 dynamic reduce(dynamic initialValue, dynamic combine(dynamic, $E)) { | |
| 32 return Collections.reduce(this, initialValue, combine); | |
| 33 } | |
| 34 | |
| 35 $if DEFINE_CONTAINS | |
| 36 bool contains($E element) => Collections.contains(this, element); | |
| 37 $else | |
| 38 // contains() defined by IDL. | |
| 39 $endif | |
| 40 | |
| 41 void forEach(void f($E element)) => Collections.forEach(this, f); | |
| 42 | |
| 43 Collection map(f($E element)) => Collections.map(this, [], f); | |
| 44 | |
| 45 Collection<$E> filter(bool f($E element)) => | |
| 46 Collections.filter(this, <$E>[], f); | |
| 47 | |
| 48 bool every(bool f($E element)) => Collections.every(this, f); | |
| 49 | |
| 50 bool some(bool f($E element)) => Collections.some(this, f); | |
| 51 | |
| 52 bool get isEmpty => this.length == 0; | |
| 53 | |
| 54 // From List<$E>: | |
| 55 $if DEFINE_LENGTH_SETTER | |
| 56 void set length(int value) { | |
| 57 throw new UnsupportedError("Cannot resize immutable List."); | |
| 58 } | |
| 59 $endif | |
| 60 | |
| 61 $if DEFINE_CLEAR | |
| 62 void clear() { | |
| 63 throw new UnsupportedError("Cannot clear immutable List."); | |
| 64 } | |
| 65 $else | |
| 66 // contains() defined by IDL. | |
| 67 $endif | |
| 68 | |
| 69 void sort([int compare($E a, $E b)]) { | |
| 70 throw new UnsupportedError("Cannot sort immutable List."); | |
| 71 } | |
| 72 | |
| 73 int indexOf($E element, [int start = 0]) => | |
| 74 Lists.indexOf(this, element, start, this.length); | |
| 75 | |
| 76 int lastIndexOf($E element, [int start]) { | |
| 77 if (start == null) start = length - 1; | |
| 78 return Lists.lastIndexOf(this, element, start); | |
| 79 } | |
| 80 | |
| 81 $E get first => this[0]; | |
| 82 | |
| 83 $E get last => this[length - 1]; | |
| 84 | |
| 85 $E removeAt(int pos) { | |
| 86 throw new UnsupportedError("Cannot removeAt on immutable List."); | |
| 87 } | |
| 88 | |
| 89 $E removeLast() { | |
| 90 throw new UnsupportedError("Cannot removeLast on immutable List."); | |
| 91 } | |
| 92 | |
| 93 void setRange(int start, int rangeLength, List<$E> from, [int startFrom]) { | |
| 94 throw new UnsupportedError("Cannot setRange on immutable List."); | |
| 95 } | |
| 96 | |
| 97 void removeRange(int start, int rangeLength) { | |
| 98 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
| 99 } | |
| 100 | |
| 101 void insertRange(int start, int rangeLength, [$E initialValue]) { | |
| 102 throw new UnsupportedError("Cannot insertRange on immutable List."); | |
| 103 } | |
| 104 | |
| 105 List<$E> getRange(int start, int rangeLength) => | |
| 106 Lists.getRange(this, start, rangeLength, <$E>[]); | |
| 107 | |
| 108 // -- end List<$E> mixins. | |
| OLD | NEW |