ImmortalList<T> class
An immutable indexable collection of objects with a length.
Operations on this list never modify the original instance but instead return new instances created from mutable lists where the operations are applied to.
ImmortalLists are Iterable. Iteration occurs over values in index order.
Internally a fixed-length List is used, regardless of what type of list is passed to the constructor.
- Implemented types
-
- Iterable<
T>
- Iterable<
- Available Extensions
Constructors
-
ImmortalList([Iterable<
T> iterable = const []]) -
Creates an ImmortalList that contains all elements of
iterable
. - ImmortalList.empty()
-
Creates an empty ImmortalList.
factory
- ImmortalList.filled(int length, T fillValue)
-
Creates an ImmortalList of the given
length
withfillValue
at each position.factory -
ImmortalList.from(Iterable<
T> iterable) -
Creates an ImmortalList that contains all elements of
iterable
.factory - ImmortalList.generate(int length, T valueGenerator(int index))
-
Generates an ImmortalList of values.
factory
-
ImmortalList.of(Iterable<
T> iterable) -
Creates an ImmortalList that contains all elements of
iterable
.factory
Properties
- first → T
-
Returns the first element.
no setteroverride
-
firstAsOptional
→ Optional<
T> -
Returns an
Optional
containing the first element of the list if the list is not empty, otherwise returnsOptional.empty
.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns
true
if there are no elements in this list.no setteroverride - isNotEmpty → bool
-
Returns
true
if there is at least one element in this list.no setteroverride -
iterator
→ Iterator<
T> -
Returns a new
Iterator
that allows iterating the elements of this list in index order.no setteroverride - last → T
-
Returns the last element.
no setteroverride
-
lastAsOptional
→ Optional<
T> -
Returns an
Optional
containing the last element of the list if the list is not empty, otherwise returnsOptional.empty
.no setter - length → int
-
Returns the number of objects in this list.
no setteroverride
-
reversed
→ ImmortalList<
T> -
Returns a list containing the objects of this list in reverse order.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → T
-
Checks that this list has only one element, and returns that element.
no setteroverride
-
singleAsOptional
→ Optional<
T> -
Returns an
Optional
containing the only element of this list if it has exactly one element, otherwise returnsOptional.empty
.no setter
Methods
-
add(
T value) → ImmortalList< T> -
Returns a copy of this list where
value
is added to the end. -
addAll(
Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list where all elements of
iterable
are added to the end. -
addIfAbsent(
T value) → ImmortalList< T> -
Returns a copy of this list where
value
is added to the end if it is not present yet. -
addOrPutWhere(
bool predicate(T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
byvalue
, or addsvalue
to the end of the list if no element satisfyingpredicate
was found. -
addOrReplaceWhere(
bool predicate(T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
byvalue
, or addsvalue
to the end of the list if no element satisfyingpredicate
was found. -
addOrSetWhere(
bool predicate(T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
byvalue
, or addsvalue
to the end of the list if no element satisfyingpredicate
was found. -
addOrUpdateWhere(
bool predicate(T value), T update(T value), T ifAbsent()) → ImmortalList< T> -
Returns a copy of this list by applying
update
on each element that fulfills the givenpredicate
, or adds the result ofifAbsent
to the list if no element satisfyingpredicate
was found. -
any(
bool predicate(T value)) → bool -
Checks whether any element of this list satisfies the given
predicate
.override -
anyIndexed(
bool predicate(int index, T value)) → bool -
Checks whether any element and its respective index satisfies the given
predicate
. -
asMap(
) → ImmortalMap< int, T> - Returns an ImmortalMap using the indices of this list as keys and the corresponding objects as values.
-
asMapOfLists<
K> (K keyGenerator(T value)) → ImmortalMap< K, ImmortalList< T> > -
Returns an ImmortalMap using the given
keyGenerator
and concatenating values with the same key. -
asMapWithKeys<
K> (K keyGenerator(T value)) → ImmortalMap< K, T> -
Returns an ImmortalMap using the given
keyGenerator
. -
asMapWithKeysIndexed<
K> (K keyGenerator(int index, T value)) → ImmortalMap< K, T> -
Returns an ImmortalMap generating keys by applying the given function
keyGenerator
to each value and its respective index. -
cast<
R> () → ImmortalList< R> -
Returns a copy of this list casting all elements to instances of
R
.override -
concatenate(
Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list concatenating
iterable
. -
contains(
Object? element) → bool -
Returns
true
if the list contains an element equal toelement
.override -
copy(
) → ImmortalList< T> - Returns a copy of this list.
-
elementAt(
int index) → T -
Returns the
index
th element.override -
elementAtAsOptional(
int index) → Optional< T> -
Returns the
index
th element wrapped by anOptional
if this element exists, otherwise returnsOptional.empty
. -
equals(
dynamic other) → bool -
Checks whether this list is equal to
other
. -
every(
bool predicate(T value)) → bool -
Checks whether every element of this list satisfies the given
predicate
.override -
everyIndexed(
bool predicate(int index, T value)) → bool -
Checks whether all elements and their respective indices satisfy the given
predicate
. -
expand<
R> (Iterable< R> f(T value)) → ImmortalList<R> -
Returns a new list expanding each element of this list into an iterable of
zero or more elements.
override
-
expandIndexed<
R> (Iterable< R> f(int index, T value)) → ImmortalList<R> -
Returns a new list expanding each element of this list into a list of zero
or more elements by applying
f
to each element and its respective index and concatenating the resulting lists. -
fillRange(
int start, int end, [T? fillValue]) → ImmortalList< T> -
Returns a copy of this list setting the objects in the range
start
inclusive toend
exclusive to the givenfillValue
. -
filter(
bool predicate(T value)) → ImmortalList< T> -
Returns a new list with all elements of this list that satisfy the given
predicate
. -
filterIndexed(
bool predicate(int index, T value)) → ImmortalList< T> -
Returns a new list containing all elements that satisfy the given
predicate
with their respective indices. -
filterMap<
R> (R? f(T value)) → ImmortalList< R> -
Returns a new list with elements that are created by calling
f
on each element of this list in iteration order and filters outnull
values. -
filterMapOptional<
R> (Optional< R> f(T value)) → ImmortalList<R> -
Returns a new list with elements that are created by calling
f
on each element of this list in iteration order and filters out empty optionals. -
filterType<
R> () → ImmortalList< R> -
Returns a new list with all elements of this list that have type
R
. -
firstWhere(
bool predicate(T value), {T orElse()?}) → T -
Returns the first element that satisfies the given predicate
predicate
.override -
firstWhereAsOptional(
bool predicate(T value)) → Optional< T> -
Returns an
Optional
containing the first element that satisfies the givenpredicate
, orOptional.empty
if none was found. -
flatMap<
R> (Iterable< R> f(T value)) → ImmortalList<R> - Returns a new list expanding each element of this list into an iterable of zero or more elements.
-
flatMapIndexed<
R> (Iterable< R> f(int index, T value)) → ImmortalList<R> -
Returns a new list expanding each element of this list into an interable
of zero or more elements by applying
f
to each element and its respective index and concatenating the resulting lists. -
flatten<
R> () → ImmortalList< R> - Flattens a list of iterables by concatenating the values in iteration order.
-
fold<
R> (R initialValue, R combine(R previousResult, T value)) → R -
Reduces the list to a single value by iteratively combining each element
of this list with an existing value.
override
-
followedBy(
Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list concatenating
iterable
.override -
forEach(
void f(T value)) → void -
Applies the function
f
to each element of this list in iteration order.override -
forEachIndexed(
void f(int index, T value)) → void -
Applies the function
f
to each element and its index of this list in iteration order. -
getRange(
int start, int end) → ImmortalList< T> -
Returns a copy of this list that contains all elements in the range
start
inclusive toend
exclusive. -
indexOf(
T value, [int start = 0]) → int -
Returns the first index of
value
in this list. -
indexWhere(
bool predicate(T value), [int start = 0]) → int -
Returns the first index in the list that satisfies the given
predicate
. -
indicesOf(
T lookupValue) → ImmortalList< int> -
Returns all indices of
lookupValue
in this list. -
indicesWhere(
bool predicate(T value)) → ImmortalList< int> -
Returns all indices in the list that satisfy the given
predicate
. -
insert(
int index, T value) → ImmortalList< T> -
Returns a copy of this list where
value
is inserted at positionindex
. -
insertAll(
int index, Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list where all objects of
iterable
are inserted at positionindex
. -
join(
[String separator = '']) → String -
Converts each element to a String and concatenates the strings.
override
-
lastIndexOf(
T value, [int? start]) → int -
Returns the last index of
value
in this list. -
lastIndexWhere(
bool predicate(T value), [int? start]) → int -
Returns the last index in the list that satisfies the given
predicate
. -
lastWhere(
bool predicate(T value), {T orElse()?}) → T -
Returns the last element that satisfies the given predicate
predicate
.override -
lastWhereAsOptional(
bool predicate(T value)) → Optional< T> -
Returns an
Optional
containing the last element that satisfies the givenpredicate
, orOptional.empty
if none was found. -
map<
R> (R f(T value)) → ImmortalList< R> -
Returns a new list with elements that are created by calling
f
on each element of this list in iteration order.override -
mapIndexed<
R> (R f(int index, T value)) → ImmortalList< R> -
Returns a new list with elements that are created by calling
f
on each element of this list and its respective index in iteration order. -
merge(
Iterable< T> other) → ImmortalList<T> -
Returns a copy of this list concatenating
other
. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
partition(
bool predicate(T value)) → Tuple2< ImmortalList< T> , ImmortalList<T> > -
Returns a tuple of two new lists by splitting the list into two depending
on the result of the given
predicate
. -
put(
int index, T value) → ImmortalList< T> -
Returns a copy of this list replacing the value at the given
index
withvalue
. -
putWhere(
bool predicate(T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
byvalue
. -
putWhereIndexed(
bool predicate(int index, T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
with its respective index byvalue
. -
reduce(
T combine(T value, T element)) → T -
Reduces the list to a single value by iteratively combining each element
of this list using the provided function
combine
.override -
remove(
Object? element) → ImmortalList< T> -
Returns a copy of this list where all occurrences of
element
are removed. -
removeAll(
Iterable< Object?> iterable) → ImmortalList<T> -
Returns a copy of this list where all values in
iterable
are removed from if present. -
removeAt(
int index) → ImmortalList< T> -
Returns a copy of this list removing the object at position
index
if present. -
removeFirst(
) → ImmortalList< T> - Returns a copy of this list where the first element is removed if the list is not empty.
-
removeFirstOccurrence(
Object? element) → ImmortalList< T> -
Returns a copy of this list where the first occurrence of
element
is removed from if present. -
removeLast(
) → ImmortalList< T> - Returns a copy of this list removing the last object if there is one, otherwise the list is returned unchanged.
-
removeLastOccurrence(
T element) → ImmortalList< T> -
Returns a copy of this list where the last occurrence of
element
is removed from if present. -
removeRange(
int start, int end) → ImmortalList< T> -
Returns a copy of this list where the objects in the range
start
inclusive toend
exclusive are removed from. -
removeWhere(
bool predicate(T value)) → ImmortalList< T> -
Returns a copy of this list where all values that satisfy the given
predicate
are removed from. -
replaceAt(
int index, T value) → ImmortalList< T> -
Returns a copy of this list replacing the value at the given
index
withvalue
. -
replaceRange(
int start, int end, Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list where all objects in the range
start
inclusive toend
exclusive are removed from and replaced by the contents ofiterable
. -
replaceWhere(
bool predicate(T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
byvalue
. -
replaceWhereIndexed(
bool predicate(int index, T value), T value) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
with its respective index byvalue
. -
retainWhere(
bool predicate(T value)) → ImmortalList< T> -
Returns a copy of this list where all values that fail to satisfy the
given
predicate
are removed from. -
set(
int index, T value) → ImmortalList< T> -
Returns a copy of this list replacing the value at the given
index
withvalue
. -
setAll(
int index, Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list replacing the objects starting at position
index
with the objects ofiterable
. -
setRange(
int start, int end, Iterable< T> iterable, [int skipCount = 0]) → ImmortalList<T> -
Returns a copy of this list where the objects in the range
start
inclusive toend
exclusive are replaced by the objects ofiterable
while skippingskipCount
objects first. -
setWhere(
bool predicate(T value), T newValue) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
bynewValue
. -
setWhereIndexed(
bool predicate(int index, T value), T newValue) → ImmortalList< T> -
Returns a copy of this list replacing each element that fulfills the given
predicate
with its respective index bynewValue
. -
shuffle(
[Random? random]) → ImmortalList< T> - Returns a copy of this list randomly shuffling the elements.
-
singleWhere(
bool predicate(T value), {T orElse()?}) → T -
Returns the single element of this list that satisfies
predicate
.override -
singleWhereAsOptional(
bool predicate(T value)) → Optional< T> -
Returns an
Optional
containing the only element satisfying the givenpredicate
if there is exactly one, otherwise returnsOptional.empty
. -
skip(
int count) → ImmortalList< T> -
Returns a copy of this list that contains all but the fist
count
elements.override -
skipWhile(
bool predicate(T value)) → ImmortalList< T> -
Returns a copy of this list containing all elements except the leading
elements while the given
predicate
is satisfied.override -
sort(
[int compare(T value, T otherValue)?]) → ImmortalList< T> -
Returns a copy of this list sorting the elements according to the order
specified by the
compare
function. -
sublist(
int start, [int? end]) → ImmortalList< T> -
Returns a copy of this containing all elements between
start
andend
. -
take(
int count) → ImmortalList< T> -
Returns a copy of this list containing the
count
first elements.override -
takeWhile(
bool predicate(T value)) → ImmortalList< T> -
Returns a copy of this list containing the leading elements satisfying the
given
predicate
.override -
toImmortalSet(
) → ImmortalSet< T> - Creates an ImmortalSet containing the same elements as this list.
-
toList(
{bool growable = true}) → List< T> -
Creates a mutable List containing the elements of this list.
override
-
toSet(
) → Set< T> -
Creates a mutable Set containing the same elements as this list.
override
-
toString(
) → String -
A string representation of this object.
override
-
updateAt(
int index, T update(T value)) → ImmortalList< T> -
Returns a copy of this list replacing the value at the given
index
by applying the functionupdate
to its value. -
updateWhere(
bool predicate(T value), T update(T value)) → ImmortalList< T> -
Returns a copy of this list by applying
update
on each element that fulfills the givenpredicate
. -
updateWhereIndexed(
bool predicate(int index, T value), T update(int index, T value)) → ImmortalList< T> -
Returns a copy of this list by applying
update
on each element and its respective index that fulfill the givenpredicate
. -
where(
bool predicate(T value)) → ImmortalList< T> -
Returns a new list with all elements of this list that satisfy the given
predicate
.override -
whereIndexed(
bool predicate(int index, T value)) → ImmortalList< T> -
Returns a new list containing all elements that satisfy the given
predicate
with their respective indices. -
whereMap<
R> (R? f(T value)) → ImmortalList< R> -
Returns a new list with elements that are created by calling
f
on each element of this list in iteration order and filters outnull
values. -
whereMapOptional<
R> (Optional< R> f(T value)) → ImmortalList<R> -
Returns a new list with elements that are created by calling
f
on each element of this list in iteration order and filters out empty optionals. -
whereType<
R> () → ImmortalList< R> -
Returns a new list with all elements of this list that have type
R
.override -
zip<
R> (Iterable< R> iterable) → ImmortalList<Tuple2< T, R> > -
Returns a new list consisting of tuples with elements from this list and
the
iterable
.
Operators
-
operator +(
Iterable< T> iterable) → ImmortalList<T> -
Returns a copy of this list concatenating
iterable
. -
operator -(
Iterable< Object?> iterable) → ImmortalList<T> -
Returns a copy of this list where all values in
iterable
are removed from if present. -
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
int index) → Optional< T> -
Returns the
index
th element wrapped by anOptional
if this element exists, otherwise returnsOptional.empty
.
Static Methods
-
castFrom<
T, R> (Iterable< T> iterable) → ImmortalList<R> -
Creates an ImmortalList by casting all elements of
iterable
to instances ofR
.override