IterableX<E> extension
Extensions for iterables
- on
-
- Iterable<
E>
- Iterable<
Properties
-
cached
→ Iterable<
E> -
Returns a new lazy Iterable that caches the computation of the current
Iterable.
no setter
- firstOrNull → E?
-
First element or
null
if the collection is empty.no setter - fourth → E
-
Fourth element.
no setter
- lastOrNull → E?
-
Last element or
null
if the collection is empty.no setter -
reversed
→ Iterable<
E> -
Returns an Iterable of the objects in this list in reverse order.
no setter
- second → E
-
Second element.
no setter
- third → E
-
Third element.
no setter
Methods
-
all(
bool predicate(E element)) → bool -
Returns true if all elements match the given
predicate
or if the collection is empty. -
append(
Iterable< E> elements) → Iterable<E> -
Returns a new lazy Iterable containing all elements of the given
elements
collection and then all elements of this collection. -
appendElement(
E element) → Iterable< E> -
Returns a new lazy Iterable containing the given
element
and then all elements of this collection. -
associate<
K, V> (MapEntry< K, V> transform(E element)) → Map<K, V> -
Returns a Map containing key-value pairs provided by
transform
function applied to elements of this collection. -
associateBy<
K> (K keySelector(E element)) → Map< K, E> -
Returns a Map containing the elements from the collection indexed by
the key returned from
keySelector
function applied to each element. -
associateWith<
V> (V valueSelector(E element)) → Map< E, V> -
Returns a Map containing the values returned from
valueSelector
function applied to each element indexed by the elements from the collection. -
asStream(
) → Stream< E> - Returns a new Stream with all elements of this collection.
-
averageBy(
num selector(E element)) → double -
Returns the average of values returned by
selector
for all elements in the collection. -
chunked(
int size) → Iterable< List< E> > -
Splits this collection into a new lazy Iterable of lists each not
exceeding the given
size
. -
chunkWhile(
bool predicate(E, E)) → Iterable< List< E> > -
Splits this collection into a lazy Iterable of chunks, where chunks are
created as long as
predicate
is true for a pair of entries. -
containsAll(
Iterable< E> collection) → bool -
Checks if all elements in the specified
collection
are contained in this collection. -
containsAny(
Iterable< E> collection) → bool -
Checks if any elements in the specified
collection
are contained in this collection. -
contentEquals(
Iterable< E> other, [bool checkEqual(E a, E b)?]) → bool -
Returns true if this collection is structurally equal to the
other
collection. -
count(
[bool predicate(E element)?]) → int -
Returns the number of elements matching the given
predicate
. -
cycle(
[int? n]) → Iterable< E> -
Returns a new lazy Iterable which iterates over this collection
n
times. -
distinct(
) → Iterable< E> - Returns a new lazy Iterable containing only distinct elements from the collection.
-
distinctBy<
R> (R selector(E element)) → Iterable< E> -
Returns a new lazy Iterable containing only elements from the collection
having distinct keys returned by the given
selector
function. -
elementAtOrDefault(
int index, E defaultValue) → E -
Returns an element at the given
index
ordefaultValue
if theindex
is out of bounds of this collection. -
elementAtOrElse(
int index, E defaultValue(int index)) → E -
Returns an element at the given
index
or the result of calling thedefaultValue
function if theindex
is out of bounds of this collection. -
elementAtOrElseNullable(
int index, E? defaultValue(int index)) → E? -
Returns an element at the given
index
or the result of calling thedefaultValue
function if theindex
is out of bounds of this collection. -
elementAtOrNull(
int index) → E? -
Returns an element at the given
index
ornull
if theindex
is out of bounds of this collection. -
except(
Iterable< E> elements) → Iterable<E> -
Returns a new lazy Iterable containing all elements of this collection
except the elements contained in the given
elements
collection. -
exceptElement(
E element) → Iterable< E> -
Returns a new lazy Iterable containing all elements of this collection
except the given
element
. -
filter(
bool predicate(E element)) → Iterable< E> -
Returns all elements matching the given
predicate
. -
filterIndexed(
bool predicate(E element, int index)) → Iterable< E> -
Returns all elements that satisfy the given
predicate
. -
filterIndexedTo(
List< E> destination, bool predicate(E element, int index)) → void -
Appends all elements matching the given
predicate
to the givendestination
. -
filterNot(
bool predicate(E element)) → Iterable< E> -
Returns all elements not matching the given
predicate
. -
filterNotIndexed(
bool predicate(E element, int index)) → Iterable< E> -
Returns all elements not matching the given
predicate
. -
filterNotNull(
) → Iterable< E> - Returns a new lazy Iterable with all elements which are not null.
-
filterNotTo(
List< E> destination, bool predicate(E element)) → void -
Appends all elements not matching the given
predicate
to the givendestination
. -
filterNotToIndexed(
List< E> destination, bool predicate(E element, int index)) → void -
Appends all elements not matching the given
predicate
to the givendestination
. -
filterTo(
List< E> destination, bool predicate(E element)) → void -
Appends all elements matching the given
predicate
to the givendestination
. -
firstOrDefault(
E defaultValue) → E -
First element or
defaultValue
if the collection is empty. -
firstOrNullWhere(
bool predicate(E element)) → E? -
Returns the first element matching the given
predicate
, ornull
if no such element was found. -
firstWhile(
bool predicate(E element)) → Iterable< E> -
/ Returns the first elements satisfying the given
predicate
. -
flatMap<
R> (Iterable< R> transform(E element)) → Iterable<R> -
Returns a new lazy Iterable of all elements yielded from results of
transform
function being invoked on each element of this collection. -
forEachIndexed(
void action(E element, int index)) → void -
Performs the given
action
on each element, providing sequential index with the element. -
groupBy<
K> (K keySelector(E element)) → Map< K, List< E> > -
Groups elements of the original collection by the key returned by the
given
keySelector
function applied to each element and returns a map. -
intersect(
Iterable< E> other) → Iterable<E> -
Returns a new lazy Iterable containing all elements that are contained
by both this collection and the
other
collection. -
joinToString(
{String separator = ', ', String transform(E element)?, String prefix = '', String postfix = '', int? limit, String truncated = '...'}) → String -
Creates a string from all the elements separated using
separator
and using the givenprefix
andpostfix
if supplied. -
lastOrElse(
E defaultValue) → E -
Last element or
defaultValue
if the collection is empty. -
lastOrNullWhere(
bool predicate(E element)) → E? -
Returns the last element matching the given
predicate
, ornull
if no such element was found. -
lastWhile(
bool predicate(E element)) → Iterable< E> -
Returns the last elements satisfying the given
predicate
. -
mapIndexed<
R> (R transform(int index, E)) → Iterable< R> -
Returns a new lazy Iterable containing the results of applying the
given
transform
function to each element and its index in the original collection. -
mapIndexedNotNull<
R> (R transform(int index, E)) → Iterable< R> -
Returns a new lazy Iterable containing only the non-null results of
applying the given
transform
function to each element and its index in the original collection. -
mapNotNull<
R> (R transform(E element)) → Iterable< R> -
Returns a new lazy Iterable containing only the non-null results of
applying the given
transform
function to each element in the original collection. -
max(
) → E -
Returns the largest element or
null
if there are no elements. -
maxBy(
Comparable selector(E element)) → E -
Returns the first element yielding the largest value of the given
selector
ornull
if there are no elements. -
maxWith(
Comparator< E> comparator) → E -
Returns the first element having the largest value according to the
provided
comparator
ornull
if there are no elements. -
min(
) → E -
Returns the smallest element or
null
if there are no elements. -
minBy(
Comparable selector(E element)) → E -
Returns the first element yielding the smallest value of the given
selector
ornull
if there are no elements. -
minWith(
Comparator< E> comparator) → E -
Returns the first element having the smallest value according to the
provided
comparator
ornull
if there are no elements. -
none(
bool predicate(E element)) → bool -
Returns true if no entries match the given
predicate
or if the collection is empty. -
onEach(
void action(E element)) → Iterable< E> - Returns a new lazy Iterable which performs the given action on each element.
-
partition(
bool predicate(E element)) → List< List< E> > -
Splits the collection into two lists according to
predicate
. -
prepend(
Iterable< E> elements) → Iterable<E> -
Returns a new lazy Iterable containing all elements of this collection
and then all elements of the given
elements
collection. -
prependElement(
E element) → Iterable< E> -
Returns a new lazy Iterable containing all elements of this collection
and then the given
element
. -
requireNoNulls(
) → void - Returns an original collection containing all the non-null elements, throwing an StateError if there are any null elements.
-
shuffled(
[Random? random]) → List< E> - Returns a new, randomly shuffled list.
-
slice(
int start, [int end = -1]) → List< E> -
Returns a new list containing elements at indices between
start
(inclusive) andend
(inclusive). -
sorted(
) → List< E> - Returns a new list with all elements sorted according to natural sort order.
-
sortedBy(
Comparable selector(E element)) → _SortedList< E> -
Returns a new list with all elements sorted according to natural sort
order of the values returned by specified
selector
function. -
sortedByDescending(
Comparable selector(E element)) → _SortedList< E> -
Returns a new list with all elements sorted according to descending
natural sort order of the values returned by specified
selector
function. -
sortedDescending(
) → List< E> - Returns a new list with all elements sorted according to descending natural sort order.
-
sortedWith(
Comparator< E> comparator) → _SortedList<E> -
Returns a new list with all elements sorted according to specified
comparator
. -
splitWhen(
bool predicate(E, E)) → Iterable< List< E> > -
Splits this collection into a lazy Iterable, where each split will be
make if
predicate
returns true for a pair of entries. -
sumBy(
num? selector(E element)) → double -
Returns the sum of all values produced by
selector
function applied to each element in the collection. -
takeFirst(
int n) → List< E> -
Returns a list containing first
n
elements. -
takeLast(
int n) → List< E> -
Returns a list containing last
n
elements. -
toHashSet(
) → HashSet< E> - Returns a new HashSet with all distinct elements of this collection.
-
toIterable(
) → Iterable< E> - Tranformations to other structures Returns a new lazy Iterable with all elements of this collection.
-
toUnmodifiable(
) → List< E> - Returns an unmodifiable List view of this collection.
-
union(
Iterable< E> other) → Iterable<E> - Returns a new lazy Iterable containing all distinct elements from both collections.
-
whereIndexed(
bool predicate(E element, int index)) → Iterable< E> -
Returns all elements that satisfy the given
predicate
. -
whereIndexedTo(
List< E> destination, bool predicate(E element, int index)) → void -
Appends all elements matching the given
predicate
to the givendestination
. -
whereNot(
bool predicate(E element)) → Iterable< E> -
Returns all elements not matching the given
predicate
. -
whereNotIndexed(
bool predicate(E element, int index)) → Iterable< E> -
Returns all elements not matching the given
predicate
. -
whereNotNull(
) → Iterable< E> - Returns a new lazy Iterable with all elements which are not null.
-
whereNotTo(
List< E> destination, bool predicate(E element)) → void -
Appends all elements not matching the given
predicate
to the givendestination
. -
whereNotToIndexed(
List< E> destination, bool predicate(E element, int index)) → void -
Appends all elements not matching the given
predicate
to the givendestination
. -
whereTo(
List< E> destination, bool predicate(E element)) → void -
Appends all elements matching the given
predicate
to the givendestination
. -
windowed(
int size, {int step = 1, bool partialWindows = false}) → Iterable< List< E> > -
Returns a new lazy Iterable of windows of the given
size
sliding along this collection with the givenstep
. -
zip<
R, V> (Iterable< R> other, V transform(E a, R b)) → Iterable<V> -
Returns a new lazy Iterable of values built from the elements of this
collection and the
other
collection with the same index.
Operators
-
operator +(
Iterable< E> elements) → List<E> -
Returns a new list containing all elements of the given
elements
collection and then all elements of this collection. -
operator -(
Iterable< E> elements) → List<E> -
Returns a new list containing all elements of this collection except the
elements contained in the given
elements
collection.