UniqueList<E> class

An implementation of List that enforces all values be unique.

Implemented types
Available extensions

Constructors

UniqueList({bool strict = false, bool nullable = true, bool growable = true})
Constructs a new UniqueList.
UniqueList.empty({bool growable = false, bool strict = false, bool nullable = true})
Creates a new empty list.
factory
UniqueList.filled(int length, {bool growable = true, bool strict = false})
Creates a list of the given length filled with null values.
factory
UniqueList.from(Iterable<E> elements, {bool growable = true, bool strict = false, bool nullable = true})
Creates a list containing all elements.
factory
UniqueList.generate(int length, Generator<E> generator, {bool growable = true, bool strict = false, bool nullable = true})
Generates a list of values.
factory
UniqueList.of(Iterable<E> elements, {bool growable = true, bool strict = false, bool nullable = true})
Creates a list from elements.
factory
UniqueList.strict()
Creates a new UniqueList that throws DuplicateValueErrors if a value is added to the list already exists in the list.
factory
UniqueList.unmodifiable(Iterable<E> elements, {bool nullable = true})
Creates an unmodifiable list containing all elements.
factory

Properties

elements List<E>
The underlying List containing all of the elements in this list.
finalinherited
first ↔ E
The first element.
getter/setter pairinherited-getter
growable bool
If true, this list is growable; otherwise, this is a fixed-length list.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
iterator Iterator<E>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last ↔ E
The last element.
getter/setter pairinherited-getter
length int
The number of objects in this list.
getter/setter pairinherited
nullable bool
If true, the list may contain multiple instances of null, otherwise, null will be treated like any other value and only one instance of null may be contained in the list.
final
reversed Iterable<E>
An Iterable of the objects in this list in reverse order.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → E
Checks that this iterable has only one element, and returns that element.
no setterinherited
strict bool
If true, a DuplicateValueError will be thrown when a value is added to the list that already exists.
final

Methods

add(E value) → void
Adds value to the end of this list, extending the length by one.
addAll(Iterable<E> iterable) → void
Appends all objects of iterable to the end of this list.
any(Test<E> test) bool
Checks whether any element of this iterable satisfies test.
inherited
asMap() Map<int, E>
An unmodifiable Map view of this list.
inherited
cast<R>() UniqueList<R>
Returns a view of this list as a list of R instances.
override
clear() → void
Removes all objects from this list; the length of the list becomes zero.
inherited
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
elementAt(int index) → E
Returns the indexth element.
inherited
every(Test<E> test) bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Expand<T, E> f) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
fillRange(int start, int end, [E? fillValue]) → void
Overwrites a range of elements with fillValue.
firstWhere(Test<E> test, {OrElse<E>? orElse}) → E
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, Fold<T, E> combine) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<E> other) Iterable<E>
Returns the lazy concatentation of this iterable and other.
forEach(ForEach<E> f) → void
Invokes action on each element of this iterable in iteration order.
inherited
getRange(int start, int end) Iterable<E>
Creates an Iterable that iterates over a range of elements.
inherited
indexOf(E element, [int start = 0]) int
The first index of element in this list.
inherited
indexWhere(Test<E> test, [int start = 0]) int
The first index in the list that satisfies the provided test.
inherited
insert(int index, E element) → void
Inserts the object at position index in this list.
insertAll(int index, Iterable<E> iterable) → void
Inserts all objects of iterable at position index in this list.
join([String separator = '']) String
Converts each element to a String and concatenates the strings.
inherited
lastIndexOf(E element, [int? start]) int
The last index of element in this list.
inherited
lastIndexWhere(Test<E> test, [int? start]) int
The last index in the list that satisfies the provided test.
inherited
lastWhere(Test<E> test, {OrElse<E>? orElse}) → E
The last element that satisfies the given predicate test.
inherited
map<T>(Mapper<T, E> f) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(Combine<E> combine) → E
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
remove(Object? value) bool
Removes the first occurrence of value from this list.
inherited
removeAt(int index) → E
Removes the object at position index from this list.
inherited
removeLast() → E
Removes and returns the last object in this list.
inherited
removeRange(int start, int end) → void
Removes a range of elements from the list.
inherited
removeWhere(Test<E> test) → void
Removes all objects from this list that satisfy test.
inherited
replaceRange(int start, int end, Iterable<E> replacement) → void
Removes the objects in the range start inclusive to end exclusive and inserts the contents of replacement in its place.
retainWhere(Test<E> test) → void
Removes all objects from this list that fail to satisfy test.
inherited
setAll(int index, Iterable<E> iterable) → void
Overwrites objects of this with the objects of iterable, starting at position index in this list.
setRange(int start, int end, Iterable<E> iterable, [int skipCount = 0]) → void
Copies the objects of iterable, skipping skipCount objects first, into the range start, inclusive, to end, exclusive, of the list.
shuffle([Random? random]) → void
Shuffles the elements of this list randomly.
inherited
singleWhere(Test<E> test, {OrElse<E>? orElse}) → E
The single element that satisfies test.
inherited
skip(int count) Iterable<E>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(Test<E> test) Iterable<E>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
sort([Compare<E>? compare]) → void
Sorts this list according to the order specified by the compare function.
inherited
sublist(int start, [int? end]) UniqueList<E>
Returns a new list containing the elements between start and end.
take(int count) Iterable<E>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(Test<E> test) Iterable<E>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toList({bool growable = true}) List<E>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<E>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
A string representation of this object.
inherited
toUniqueList({bool growable = true, bool strict = true, bool nullable = true}) UniqueList<E>
Creates a UniqueList containing the elements of this list.
where(Test<E> test) Iterable<E>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator +(List<E> other) UniqueList<E>
Returns the concatenation of this list and other.
operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) → E
The object at the given index in the list.
inherited
operator []=(int index, E value) → void
Sets the value at the given index in the list to value or throws a RangeError if index is out of bounds.

Static Methods

castFrom<S, T>(List<S> source, {bool strict = false, bool nullable = true, bool growable = true}) UniqueList<T>
Adapts source to be a UniqueList<T>.
override