Dart Documentationdart.pkg.collection.wrappersNonGrowableListMixin<E>

NonGrowableListMixin<E> abstract class

Mixin class that implements a throwing version of all list operations that change the List's length.

abstract class NonGrowableListMixin<E> implements List<E> {
 static void _throw() {
   throw new UnsupportedError(
       "Cannot change the length of a fixed-length list");
 }

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void set length(int newLength) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 bool add(E value) {
   _throw();
 }

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void addAll(Iterable<E> iterable) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void insert(int index, E element) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void insertAll(int index, Iterable<E> iterable) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 bool remove(Object value) { _throw(); }

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 E removeAt(int index) { _throw(); }

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 E removeLast() { _throw(); }

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void removeWhere(bool test(E element)) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void retainWhere(bool test(E element)) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void removeRange(int start, int end) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void replaceRange(int start, int end, Iterable<E> iterable) => _throw();

 /**
  * Throws an [UnsupportedError];
  * operations that change the length of the list are disallowed.
  */
 void clear() => _throw();
}

Implements

List<E>

Properties

final E first #

inherited from Iterable

Returns the first element.

If this is empty throws a StateError. Otherwise this method is equivalent to this.elementAt(0)

E get first;

final bool isEmpty #

inherited from Iterable

Returns true if there is no element in this collection.

bool get isEmpty;

final bool isNotEmpty #

inherited from Iterable

Returns true if there is at least one element in this collection.

bool get isNotEmpty;

final Iterator<E> iterator #

inherited from Iterable

Returns an Iterator that iterates over this Iterable object.

Iterator<E> get iterator;

final E last #

inherited from Iterable

Returns the last element.

If this is empty throws a StateError.

E get last;

abstract int get length #

inherited from List

Returns the number of objects in this list.

The valid indices for a list are 0 through length - 1.

void set length(int newLength) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void set length(int newLength) => _throw();

final Iterable<E> reversed #

inherited from List

Returns an Iterable of the objects in this list in reverse order.

Iterable<E> get reversed;

final E single #

inherited from Iterable

Returns the single element in this.

If this is empty or has more than one element throws a StateError.

E get single;

Operators

abstract E operator [](int index) #

inherited from List

Returns the object at the given index in the list or throws a RangeError if index is out of bounds.

abstract void operator []=(int index, E value) #

inherited from List

Sets the value at the given index in the list to value or throws a RangeError if index is out of bounds.

Methods

bool add(E value) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

bool add(E value) {
 _throw();
}

void addAll(Iterable<E> iterable) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void addAll(Iterable<E> iterable) => _throw();

abstract bool any(bool test(E element)) #

inherited from Iterable

Returns true if one element of this collection satisfies the predicate test. Returns false otherwise.

abstract Map<int, E> asMap() #

inherited from List

Returns an unmodifiable Map view of this.

The map uses the indices of this list as keys and the corresponding objects as values. The Map.keys Iterable iterates the indices of this list in numerical order.

List<String> words = ['fee', 'fi', 'fo', 'fum'];
Map<int, String> map = words.asMap();
map[0] + map[1];   // 'feefi';
map.keys.toList(); // [0, 1, 2, 3]

void clear() #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void clear() => _throw();

abstract bool contains(Object element) #

inherited from Iterable

Returns true if the collection contains an element equal to element.

abstract E elementAt(int index) #

inherited from Iterable

Returns the indexth element.

If this has fewer than index elements throws a RangeError.

Note: if this does not have a deterministic iteration order then the function may simply return any element without any iteration if there are at least index elements in this.

abstract bool every(bool test(E element)) #

inherited from Iterable

Returns true if every elements of this collection satisify the predicate test. Returns false otherwise.

abstract Iterable expand(Iterable f(E element)) #

inherited from Iterable

Expands each element of this Iterable into zero or more elements.

The resulting Iterable runs through the elements returned by f for each element of this, in order.

The returned Iterable is lazy, and calls f for each element of this every time it's iterated.

abstract void fillRange(int start, int end, [E fillValue]) #

inherited from List

Sets the objects in the range start inclusive to end exclusive to the given fillValue.

An error occurs if start.. end is not a valid range for this.

abstract E firstWhere(bool test(E element), {E orElse()}) #

inherited from Iterable

Returns the first element that satisfies the given predicate test.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

abstract dynamic fold(initialValue, combine(previousValue, E element)) #

inherited from Iterable

Reduces a collection to a single value by iteratively combining each element of the collection with an existing value using the provided function.

Use initialValue as the initial value, and the function combine to create a new value from the previous one and an element.

Example of calculating the sum of an iterable:

iterable.fold(0, (prev, element) => prev + element);

abstract void forEach(void f(E element)) #

inherited from Iterable

Applies the function f to each element of this collection.

abstract Iterable<E> getRange(int start, int end) #

inherited from List

Returns an Iterable that iterates over the objects in the range start inclusive to end exclusive.

An error occurs if end is before start.

An error occurs if the start and end are not valid ranges at the time of the call to this method. The returned Iterable behaves like skip(start).take(end - start). That is, it does not throw exceptions if this changes size.

List<String> colors = ['red', 'green', 'blue', 'orange', 'pink'];
Iterable<String> range = colors.getRange(1, 4);
range.join(', ');  // 'green, blue, orange'
colors.length = 3;
range.join(', ');  // 'green, blue'

abstract int indexOf(E element, [int start = 0]) #

inherited from List

Returns the first index of element in this list.

Searches the list from index start to the end of the list. The first time an object o is encountered so that o == element, the index of o is returned.

List<String> notes = ['do', 're', 'mi', 're'];
notes.indexOf('re');    // 1
notes.indexOf('re', 2); // 3

Returns -1 if element is not found.

notes.indexOf('fa');    // -1

void insert(int index, E element) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void insert(int index, E element) => _throw();

void insertAll(int index, Iterable<E> iterable) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void insertAll(int index, Iterable<E> iterable) => _throw();

String join([String separator = ""]) #

inherited from Iterable

Converts each element to a String and concatenates the strings.

Converts each element to a String by calling Object.toString on it. Then concatenates the strings, optionally separated by the separator string.

String join([String separator = ""]) {
 StringBuffer buffer = new StringBuffer();
 buffer.writeAll(this, separator);
 return buffer.toString();
}

abstract int lastIndexOf(E element, [int start]) #

inherited from List

Returns the last index of element in this list.

Searches the list backwards from index start to 0.

The first time an object o is encountered so that o == element, the index of o is returned.

List<String> notes = ['do', 're', 'mi', 're'];
notes.lastIndexOf('re', 2); // 1

If start is not provided, this method searches from the end of the list./Returns

notes.lastIndexOf('re');  // 3

Returns -1 if element is not found.

notes.lastIndexOf('fa');  // -1

abstract E lastWhere(bool test(E element), {E orElse()}) #

inherited from Iterable

Returns the last element that satisfies the given predicate test.

If none matches, the result of invoking the orElse function is returned. By default, when orElse is null, a StateError is thrown.

abstract Iterable map(f(E element)) #

inherited from Iterable

Returns a lazy Iterable where each element e of this is replaced by the result of f(e).

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function f will not be invoked. The transformed elements will not be cached. Iterating multiple times over the the returned Iterable will invoke the supplied function f multiple times on the same element.

abstract E reduce(E combine(E value, E element)) #

inherited from Iterable

Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.

Example of calculating the sum of an iterable:

iterable.reduce((value, element) => value + element);

bool remove(Object value) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

bool remove(Object value) { _throw(); }

E removeAt(int index) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

E removeAt(int index) { _throw(); }

E removeLast() #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

E removeLast() { _throw(); }

void removeRange(int start, int end) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void removeRange(int start, int end) => _throw();

void removeWhere(bool test(E element)) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void removeWhere(bool test(E element)) => _throw();

void replaceRange(int start, int end, Iterable<E> iterable) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void replaceRange(int start, int end, Iterable<E> iterable) => _throw();

void retainWhere(bool test(E element)) #

Throws an UnsupportedError; operations that change the length of the list are disallowed.

void retainWhere(bool test(E element)) => _throw();

abstract void setAll(int index, Iterable<E> iterable) #

inherited from List

Overwrites objects of this with the objects of iterable, starting at position index in this list.

List<String> list = ['a', 'b', 'c'];
list.setAll(1, ['bee', 'sea']);
list.join(', '); // 'a, bee, sea'

This operation does not increase the length of this.

The index must be non-negative and no greater than length.

The iterable must not have more elements than what can fit from index to length.

If iterable is based on this list, its values may change /during/ the setAll operation.

abstract void setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) #

inherited from List

Copies the objects of iterable, skipping skipCount objects first, into the range start, inclusive, to end, exclusive, of the list.

List<int> list1 = [1, 2, 3, 4];
List<int> list2 = [5, 6, 7, 8, 9];
// Copies the 4th and 5th items in list2 as the 2nd and 3rd items
// of list1.
list1.setRange(1, 3, list2, 3);
list1.join(', '); // '1, 8, 9, 4'

The start and end indices must satisfy 0 ≤ start ≤ end ≤ length. If start equals end, this method has no effect.

The iterable must have enough objects to fill the range from start to end after skipping skipCount objects.

If iterable is this list, the operation will copy the elements originally in the range from skipCount to skipCount + (end - start) to the range start to end, even if the two ranges overlap.

If iterable depends on this list in some other way, no guarantees are made.

abstract void shuffle([Random random]) #

inherited from List

Shuffles the elements of this list randomly.

abstract E singleWhere(bool test(E element)) #

inherited from Iterable

Returns the single element that satisfies test. If no or more than one element match then a StateError is thrown.

abstract Iterable<E> skip(int n) #

inherited from Iterable

Returns an Iterable that skips the first n elements.

If this has fewer than n elements, then the resulting Iterable is empty.

It is an error if n is negative.

abstract Iterable<E> skipWhile(bool test(E value)) #

inherited from Iterable

Returns an Iterable that skips elements while test is satisfied.

The filtering happens lazily. Every new Iterator of the returned Iterable iterates over all elements of this.

As long as the iterator's elements satisfy test they are discarded. Once an element does not satisfy the test the iterator stops testing and uses every later element unconditionally. That is, the elements of the returned Iterable are the elements of this starting from the first element that does not satisfy test.

abstract void sort([int compare(E a, E b)]) #

inherited from List

Sorts this list according to the order specified by the compare function.

The compare function must act as a Comparator.

List<String> numbers = ['one', 'two', 'three', 'four'];
// Sort from shortest to longest.
numbers.sort((x, y) => x.length.compareTo(y.length));
numbers.join(', '); // 'one, two, four, three'

The default List implementations use Comparable.compare if compare is omitted.

List<int> nums = [13, 2, -11];
nums.sort();
     nums.join(', '); // '-11, 2, 13'

abstract List<E> sublist(int start, [int end]) #

inherited from List

Returns a new list containing the objects from start inclusive to end exclusive.

List<String> colors = ['red', 'green', 'blue', 'orange', 'pink'];
colors.sublist(1, 3); // ['green', 'blue']

If end is omitted, the length of this is used.

colors.sublist(1);  // ['green', 'blue', 'orange', 'pink']

An error occurs if start is outside the range 0 .. length or if end is outside the range start .. length.

abstract Iterable<E> take(int n) #

inherited from Iterable

Returns an Iterable with at most n elements.

The returned Iterable may contain fewer than n elements, if this contains fewer than n elements.

It is an error if n is negative.

abstract Iterable<E> takeWhile(bool test(E value)) #

inherited from Iterable

Returns an Iterable that stops once test is not satisfied anymore.

The filtering happens lazily. Every new Iterator of the returned Iterable starts iterating over the elements of this.

When the iterator encounters an element e that does not satisfy test, it discards e and moves into the finished state. That is, it does not get or provide any more elements.

abstract List<E> toList({bool growable: true}) #

inherited from Iterable

Creates a List containing the elements of this Iterable.

The elements are in iteration order. The list is fixed-length if growable is false.

abstract Set<E> toSet() #

inherited from Iterable

Creates a Set containing the elements of this Iterable.

abstract Iterable<E> where(bool test(E element)) #

inherited from Iterable

Returns a lazy Iterable with all elements that satisfy the predicate test.

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function test will not be invoked. Iterating will not cache results, and thus iterating multiple times over the returned Iterable will invoke the supplied function test multiple times on the same element.