IList<T> class
abstract
- Inheritance
-
- Object
- ImmutableCollection<
IList< T> > - IList
- Implemented types
-
- Iterable<
T>
- Iterable<
- Available extensions
- Annotations
-
- @immutable
Constructors
-
IList([Iterable<
T> ? iterable]) -
Create an IList from an
iterable
, with the default configuration. Fast, if the iterable is another IList.factory -
IList.fromISet(ISet<
T> iset, {int compare(T a, T b)?, required ConfigList? config}) -
Special IList constructor from ISet.
factory
- IList.fromJson(dynamic json, T fromJsonT(Object?))
-
Converts from JSon. Json serialization support for json_serializable with @JsonSerializable.
factory
-
IList.unsafe(List<
T> list, {required ConfigList config}) -
Unsafe constructor. Use this at your own peril.
factory
-
IList.withConfig(Iterable<
T> ? iterable, ConfigList config) -
Create an IList from any Iterable and a ConfigList.
Fast, if the Iterable is another IList.
If
iterable
is null, return an empty IList.factory
Properties
- config → ConfigList
-
no setter
- first → T
-
Returns the first element.
Throws a StateError if the list is empty.
no setteroverride
- firstOrNull → T?
-
Returns the first element, or
null
if the list is empty.no setter -
flush
→ IList<
T> -
Flushes the list, if necessary. Chainable getter.
If the list is already flushed, don't do anything.
no setteroverride
- hashCode → int
-
The hash code for this object.
no setteroverride
- head → T
-
Returns the first element of this Iterable
no setter
-
init
→ Iterable<
T> -
Returns an Iterable that is the original iterable without the last element
no setter
- isDeepEquals → bool
-
See also: ConfigList
no setter
- isEmpty → bool
-
Returns
true
if there are no elements in this collection.no setteroverride - isFlushed → bool
-
Whether this list is already flushed or not.
no setteroverride
- isIdentityEquals → bool
-
See also: ConfigList
no setter
- isNotEmpty → bool
-
Returns
true
if there is at least one element in this collection.no setteroverride -
iterator
→ Iterator<
T> -
Returns a new
Iterator
that allows iterating the elements of this IList.no setteroverride - last → T
-
Returns the last element.
Throws a StateError if the list is empty.
no setteroverride
- lastOrNull → T?
-
Returns the last element, or
null
if the list is empty.no setter - length → int
-
The number of objects in this list.
no setteroverride
-
reversed
→ IList<
T> -
Returns an Iterable of the objects in 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 iterable has only one element, and returns that element.
Throws a StateError if the list is empty or has more than one element.
no setteroverride
- singleOrNull → T?
-
Checks that the list has only one element, and returns that element.
Return
null
if the list is empty or has more than one element.no setter -
tail
→ Iterable<
T> -
Returns an Iterable that is the original iterable without head, aka first element
no setter
-
unlock
→ List<
T> -
Unlocks the list, returning a regular (mutable, growable) List. This
list is "safe", in the sense that is independent from the original IList.
no setter
-
unlockLazy
→ List<
T> -
Unlocks the list, returning a safe, modifiable (mutable) List.
Using this is very fast at first, since it makes no copies of the IList
items. However, if and only if you use a method that mutates the list,
like add, it will unlock internally (make a copy of all IList items). This is
transparent to you, and will happen at most only once. In other words,
it will unlock the IList, lazily, only if necessary.
If you never mutate the list, it will be very fast to lock this list
back into an IList.
no setter
-
unlockView
→ List<
T> -
Unlocks the list, returning a safe, unmodifiable (immutable) List view.
The word "view" means the list is backed by the original IList.
Using this is very fast, since it makes no copies of the IList items.
However, if you try to use methods that modify the list, like add,
it will throw an UnsupportedError.
It is also very fast to lock this list back into an IList.
no setter
-
withDeepEquals
→ IList<
T> -
Creates a list with
deepEquals
(compares all list items by equality).no setter -
withIdentityEquals
→ IList<
T> -
Creates a list with
identityEquals
(compares the internals byidentity
).no setter
Methods
-
add(
T item) → IList< T> -
Return a new list with
item
added to the end of the current list, (thus extending the length by one). -
addAll(
Iterable< T> items) → IList<T> -
Returns a new list with all
items
added to the end of the current list, (thus extending the length by the length of items). -
any(
Predicate< T> test) → bool -
Checks whether any element of this iterable satisfies
test
.override -
asMap(
) → IMap< int, T> -
Returns an IMap view of this list.
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. -
cast<
R> () → Iterable< R> -
Returns a list of
R
instances. If this list contains instances which cannot be cast toR
, it will throw an error.override -
clear(
) → IList< T> - Returns an empty list with the same configuration.
-
contains(
covariant T? element) → bool -
Returns
true
if the collection contains an element equal toelement
,false
otherwise.override -
corresponds<
U> (Iterable< U> others, EQ eq) → bool - Return true if length match and all Eq are true
-
count(
Predicate< T> p) → int - Positives predicate results count
-
divideIn2(
bool test(T item)) → IListOf2< IList< T> > -
Divides the list into two.
The first one contains all items which satisfy the provided
test
. The last one contains all the other items. The relative order of the items will be maintained. -
elementAt(
int index) → T -
Returns the
index
th element. This is the same as using the [] operator. See also: get and getOrNull.override -
equalItems(
covariant Iterable? other) → bool -
Will return
true
only if the IList items are equal to the iterable items, and in the same order. This may be slow for very large lists, since it compares each item, one by one. You can compare the list with ordered sets, but unordered sets will throw aStateError
. To compare the IList with unordered sets, try the unorderedEqualItems method.override -
equalItemsAndConfig(
IList? other) → bool -
Will return
true
only if the list items are equal and in the same order, and the list configurations are equal. This may be slow for very large lists, since it compares each item, one by one.override -
every(
Predicate< T> test) → bool -
Checks whether every element of this iterable satisfies
test
.override -
expand<
E> (Iterable< E> f(T)) → Iterable<E> -
Expands each element of this Iterable into zero or more elements.
override
-
fillRange(
int start, int end, [T? fillValue]) → IList< T> -
Sets the objects in the range
start
inclusive toend
exclusive to the givenfillValue
. -
firstOr(
T orElse) → T -
Returns the first element, or
orElse
if the list is empty. -
firstWhere(
Predicate< T> test, {T orElse()?}) → T -
Iterates through elements and returns the first to satisfy
test
.override -
fold<
E> (E initialValue, E combine(E previousValue, T element)) → E -
Reduces a collection to a single value by iteratively combining eac element of the collection
with an existing value.
override
-
followedBy(
Iterable< T> other) → Iterable<T> -
Returns the lazy concatenation of this iterable and
other
.override -
forEach(
void f(T element)) → void -
Applies the function
f
to each element of this collection in iteration order.override -
get(
int index, {T orElse(int index)?}) → T -
Returns the
index
th element. If that index doesn't exist (negative, or out of range), will return the result of callingorElse
. In this case, iforElse
is not provided, will throw an error. -
getAndMap(
int index, T map(int index, bool inRange, T? value)) → T -
Gets the
index
th element, and then apply themap
function to it, returning the result. If that index doesn't exist (negative, or out of range), will themap
method will be called withinRange
false andvalue
null. -
getOrNull(
int index) → T? -
Returns the
index
th element. If that index doesn't exist (negative or out of range), will return null. This method will never throw an error. -
getRange(
int start, int end) → Iterable< T> -
Returns an Iterable that iterates over the objects in the range
start
inclusive toend
exclusive. -
indexOf(
T element, [int start = 0]) → int -
Returns the index of the first
element
in the list. -
indexWhere(
Predicate< T> test, [int start = 0]) → int -
Returns the first index in the list that satisfies the provided
test
. -
inits(
) → Iterable< Iterable< T> > -
inRange(
int index) → bool -
Returns
true
if the givenindex
is valid (between0
andlength - 1
). -
insert(
int index, T element) → IList< T> -
Inserts the object at position
index
in this list and returns a new immutable list. -
insertAll(
int index, Iterable< T> iterable) → IList<T> -
Inserts all objects of
iterable
at positionindex
in this list. -
join(
[String separator = ""]) → String -
Converts each element to a String and concatenates the strings with the
separator
in-between each concatenation.override -
lastIndexOf(
T element, [int? start]) → int -
Returns the last index of
element
in this list. -
lastIndexWhere(
Predicate< T> test, [int? start]) → int -
Returns the last index in the list that satisfies the provided
test
. -
lastOr(
T orElse) → T -
Returns the last element, or
orElse
if the list is empty. -
lastWhere(
Predicate< T> test, {T orElse()?}) → T -
Returns the last element that satisfies the given predicate
test
.override -
lengthCompare(
Iterable others) → bool -
Compare with
others
length -
map<
E> (E f(T element), {ConfigList? config}) → Iterable< E> -
Returns a new lazy Iterable with elements that are created by calling
f
on each element of this Iterable in iteration order.override -
maxLength(
int maxLength, {int priority(T a, T b)?}) → IList< T> -
If the list has more than
maxLength
elements, remove the last elements so it remains with onlymaxLength
elements. If the list hasmaxLength
or less elements, doesn't change anything. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
process(
{bool test(IList< T> list, int index, T item)?, required Iterable<T> ? convert(IList<T> list, int index, T item)}) → IList<T> - Allows for complex processing of a list.
-
put(
int index, T value) → IList< T> -
This is the equivalent to
void operator []=(int index, T value);
Sets the value at the givenindex
in the list tovalue
or throws a RangeError ifindex
is out of bounds. -
reduce(
T combine(T value, T element)) → T -
Reduces a collection to a single value by iteratively combining elements of the collection
using the provided function.
override
-
remove(
T item) → IList< T> -
Removes the first occurrence of
item
from this IList. -
removeAll(
Iterable< T?> items) → IList<T> -
Removes all occurrences of all
items
from this list. Same as calling removeMany for each item initems
. -
removeAt(
int index, [Output< T> ? removedItem]) → IList<T> -
Removes the object at position
index
from this list. -
removeDuplicates(
) → IList< T> - Removes duplicates (but keeps items which appear only once, plus the first time other items appear).
-
removeLast(
[Output< T> ? removedItem]) → IList<T> -
Removes the last object from this list.
This method reduces the length of
this
by one. -
removeMany(
T item) → IList< T> -
Removes all occurrences of
item
from this list. -
removeNulls(
) → IList< T> - Removes all nulls from this list.
-
removeNullsAndDuplicates(
) → IList< T> - Removes duplicates (but keeps items which appear only once, plus the first time other items appear).
-
removeRange(
int start, int end) → IList< T> -
Removes the objects in the range
start
inclusive toend
exclusive. -
removeWhere(
Predicate< T> test) → IList<T> -
Removes all objects from this list that satisfy
test
. -
replace(
int index, T value) → IList< T> -
The replace method is the equivalent of
operator []=
for the IList. -
replaceAll(
{required T from, required T to}) → IList< T> -
Finds all occurrences of
from
, and replace them withto
. -
replaceAllWhere(
Predicate< T> test, T to) → IList<T> -
Finds all items that satisfy the provided
test
, and replace it withto
. -
replaceFirst(
{required T from, required T to}) → IList< T> -
Finds the first occurrence of
from
, and replace it withto
. -
replaceFirstWhere(
bool test(T item), T to, {bool addIfNotFound = false}) → IList< T> -
Finds the first item that satisfies the provided
test
, and replace it withto
. -
replaceRange(
int start, int end, Iterable< T> replacement) → IList<T> -
Removes the objects in the range
start
inclusive toend
exclusive and inserts the contents ofreplacement
in its place. -
retainWhere(
Predicate< T> test) → IList<T> -
Removes all objects from this list that fail to satisfy
test
. -
same(
IList< T> ? other) → bool -
Will return
true
only if the lists internals are the same instances (comparing by identity). This will be fast even for very large lists, since it doesn't compare each item.override -
setAll(
int index, Iterable< T> iterable) → IList<T> -
Overwrites objects of
this
with the objects ofiterable
, starting at positionindex
in this list. -
setRange(
int start, int end, Iterable< T> iterable, [int skipCount = 0]) → IList<T> -
Copies the objects of
iterable
, skippingskipCount
objects first, into the rangestart
, inclusive, toend
, exclusive, of the list. -
shuffle(
[Random? random]) → IList< T> - Shuffles the elements of this list randomly.
-
singleOr(
T orElse) → T -
Checks if the list has only one element, and returns that element.
Return
null
if the list is empty or has more than one element. -
singleWhere(
Predicate< T> test, {T orElse()?}) → T -
Returns the single element that satisfies
test
.override -
skip(
int count) → Iterable< T> -
Returns an Iterable that provides all but the first
count
elements.override -
skipWhile(
bool test(T value)) → Iterable< T> -
Returns an Iterable that skips leading elements while
test
is satisfied.override -
sort(
[int compare(T a, T b)?]) → IList< T> -
Sorts this list according to the order specified by the
compare
function. -
sortLike(
Iterable< T> ordering) → IList<T> -
Sorts this list according to the order specified by the
ordering
iterable. Items which don't appear inordering
will be included in the end, in no particular order. -
sortOrdered(
[int compare(T a, T b)?]) → IList< T> -
Sorts this list according to the order specified by the
compare
function. -
sortReversed(
[int compare(T a, T b)?]) → IList< T> - Sorts this list in reverse order in relation to the default sort method.
-
span(
Predicate< T> p) → Tuple2<Iterable< T> , Iterable<T> > - Split list based on predicate p. (takeWhile p, dropWhile p)
-
splitAt(
int index) → Tuple2< Iterable< T> , Iterable<T> > - Split the List at specified index
-
sublist(
int start, [int? end]) → IList< T> -
Returns a new list containing the elements between
start
andend
. -
tails(
) → Iterable< Iterable< T> > -
take(
int count) → Iterable< T> -
Returns an Iterable of the
count
first elements of this iterable.override -
takeWhile(
bool test(T value)) → Iterable< T> -
Returns an Iterable of the leading elements satisfying
test
.override -
toggle(
T element) → IList< T> - Removes the first instance of the element, if it exists in the list. Otherwise, adds it to the list.
-
toJson(
Object? toJsonT(T)) → Object - Converts to JSon. Json serialization support for json_serializable with @JsonSerializable.
-
toList(
{bool growable = true}) → List< T> -
Creates a List containing the elements of this IList.
override
-
toSet(
) → Set< T> -
Creates a Set containing the same elements as this IList.
override
-
toString(
[bool? prettyPrint]) → String -
Returns a string representation of (some of) the elements of
this
.override -
unorderedEqualItems(
covariant Iterable? other) → bool -
Will return
true
only if the IList and the iterable items have the same number of elements, and the elements of the IList can be paired with the elements of the iterable, so that each pair is equal. This may be slow for very large lists, since it compares each item, one by one. -
updateById(
Iterable< T> newItems, dynamic id(T item)) → IList<T> -
Returns a new list where
newItems
are added or updated, by theirid
(and theid
is a function of the item), like so: -
where(
Predicate< T> test) → Iterable<T> -
Returns an Iterable with all elements that satisfy the predicate
test
.override -
whereMoveToTheEnd(
bool test(T item)) → IList< T> -
Moves all items that satisfy the provided
test
to the end of the list. Keeps the relative order of the moved items. -
whereMoveToTheStart(
bool test(T item)) → IList< T> -
Moves all items that satisfy the provided
test
to the start of the list. Keeps the relative order of the moved items. -
whereNot(
Predicate< T> test) → Iterable<T> -
Returns an Iterable with all elements that doest NOT satisfy the predicate
test
. -
whereType<
E> () → Iterable< E> -
Returns an Iterable with all elements that have type
E
.override -
withConfig(
ConfigList config) → IList< T> -
Creates a new list with the given
config
. -
withConfigFrom(
IList< T> other) → IList<T> -
Returns a new list with the contents of the present IList,
but the config of
other
. -
zip(
Iterable< T> otherIterable) → Iterable<Tuple2< T, T> > - Aggregate two sources trimming by the shortest source
-
zipAll<
U> (Iterable< U> otherIterable, {T currentFill(int index)?, U otherFill(int index)?}) → Iterable<Tuple2< T?, U?> > -
Aggregate two sources based on the longest source.
Missing elements can be completed by passing a
currentFill
andotherFill
methods or will be at null by default -
zipWithIndex(
) → Iterable< Tuple2< int, T> > - Aggregate each element with corresponding index
Operators
-
operator +(
Iterable< T> other) → IList<T> -
Returns the concatenation of this list and
other
. Returns a new list containing the elements of this list followed by the elements ofother
. -
operator ==(
Object other) → bool -
If isDeepEquals configuration is
true
: Will returntrue
only if the list items are equal (and in the same order), and the list configurations are equal. This may be slow for very large lists, since it compares each item, one by one.If isDeepEquals configuration is
false
: Will returntrue
only if the lists internals are the same instances (comparing by identity). This will be fast even for very large lists, since it doesn't compare each item.override -
operator [](
int index) → T -
Returns the object at the given
index
in the list or throws a RangeError ifindex
is out of bounds.
Static Properties
- defaultConfig ↔ ConfigList
-
Global configuration that specifies if, by default, the ILists
use equality or identity for their operator ==.
By default
isDeepEquals: true
(lists are compared by equality) andcacheHashCode = true
.getter/setter pair - flushFactor ↔ int
-
Indicates the number of operations an IList may perform
before it is eligible for auto-flush. Must be larger than
0
.getter/setter pair
Static Methods
-
iterate<
U> (U base, int count, Op< U> op) → IList<U> - Apply Op on previous state of base and return all results
-
iterateWhile<
U> (U base, Predicate< U> test, Op<U> op) → IList<U> - Apply Op on previous state of base while predicate pass then return all results
-
orNull<
T> (Iterable< T> ? iterable, [ConfigList? config]) → IList<T> ? -
If Iterable is
null
, returnnull
. -
resetAllConfigurations(
) → void -
See also: ImmutableCollection, ImmutableCollection.lockConfig,
ImmutableCollection.isConfigLocked,flushFactor, defaultConfig
override
-
tabulate<
U> (int count, U on(int at)) → Iterable< U> -
tabulate2<
U> (int count0, int count1, U on(int at0, int at1)) → Iterable< Iterable< U> > -
tabulate3<
U> (int count0, int count1, int count2, U on(int at0, int at1, int at2)) → Iterable< Iterable< Iterable< >U> > -
tabulate4<
U> (int count0, int count1, int count2, int count3, U on(int at0, int at1, int at2, int at3)) → Iterable< Iterable< Iterable< >Iterable< >U> > -
tabulate5<
U> (int count0, int count1, int count2, int count3, int count4, U on(int at0, int at1, int at2, int at3, int at4)) → Iterable< Iterable< Iterable< >Iterable< >Iterable< >U> >