IterableBasics2<T> extension
Properties
-
lastIndex
→ int?
-
Returns the last accessible index. If collection is empty this returns
null
.
no setter
Methods
-
associate<K, V>(MapEntry<K, V> transform(T element))
→ Map<K, V>
-
Returns a map that contains MapEntrys provided by a
transform
function.
-
associateBy<K>(K keySelector(T element))
→ Map<K, T>
-
Returns a map where every
element
is associated by a key produced from
the keySelector
function.
-
associateWith<V>(V valueSelector(T element))
→ Map<T, V>
-
Returns a map where every
element
is used as a key that is associated
with a value produced by the valueSelector
function.
-
averageBy(num selector(T))
→ double?
-
Returns the average value (arithmetic mean) of all values produces by the
selector
function that is applied to each element.
-
chunked(int size, {T fill()?})
→ Iterable<List<T>>
-
Splits the elements into lists of the specified
size
.
-
count([bool test(T element)?])
→ int
-
Returns the number of elements that matches the
test
.
-
elementAtOrElse(int index, T orElse())
→ T
-
Returns the
index
th element. If the index is out of bounds the orElse
supplier function is called to provide a value.
-
elementAtOrNull(int index)
→ T
-
Returns the
index
th element. If the index is out of bounds it will
return null
.
-
filter(bool test(T element))
→ Iterable<T>
-
Returns a new Iterable with all elements that satisfy the
predicate
test
.
-
firstOrElse(T orElse())
→ T
-
Returns the first element. If there is no first element the
orElse
supplier function is called to provide a value.
-
firstOrNull()
→ T
-
Returns the first element. If there is no first element it will
return
null
.
-
forEachIndexed(void funcIndexValue(int index, T element))
→ void
-
Applies the function
funcIndexValue
to each element of this collection
in iteration order. The function receives the element index as first
parameter index
and the element
as the second parameter.
-
groupBy<K, V>(K keySelector(T element), {V valueTransform(T element)?})
→ Map<K, List<V>>
-
Groups the elements of the list into a map by a key
that is defined by a
keySelector
function.
-
lastOrElse(T orElse())
→ T
-
Returns the last element. If there is no last element the
orElse
supplier function is called to provide a value.
-
lastOrNull()
→ T
-
Returns the last element. If there is no last element it will
return
null
.
-
mapIndexed<U>(U transformer(T currentValue, int index))
→ Iterable<U>
-
Just like map, but with access to the element's current index.
-
maximumBy(Comparator<T> comparator)
→ T?
-
Returns the maximum value based on the
comparator
function.
-
minimumBy(Comparator<T> comparator)
→ T?
-
Returns the minimal value based on the
comparator
function.
-
onEach(void action(T element))
→ Iterable<T>
-
Applies the given
action
on each element and also returns the
whole Iterable without modifying it.
-
onEachIndexed(void action(T element, int index))
→ Iterable<T>
-
Applies the given
action
on each element and also returns the
whole Iterable without modifying it. The action
takes a second
parameter index
matching the element index.
-
pickOne([Random? random])
→ T
-
Returns a random item.
The randomness can be customized by setting
random
.
-
pickSome(int count, [Random? random])
→ List<T>
-
Returns an List of
count
random items.
The randomness can be customized by setting random
.
-
replaceFirstWhere(bool comparator(T currentValue), T newValue)
→ Iterable<T>
-
Replaces the first element that matches the
comparator
with newValue
.
-
replaceWhere(bool comparator(T currentValue), T newValue)
→ Iterable<T>
-
Replaces every element that matches the
comparator
with newValue
.
-
sortedBy(Comparator<T> comparator)
→ List<T>
-
Returns this as sorted list using the
comparator
function.
-
sortedByNum(num valueProvider(T element))
→ List<T>
-
Returns this as sorted list using the
valueProvider
function that produces
numerical values as base for sorting.
-
sortedByString(String valueProvider(T element))
→ List<T>
-
Returns this as sorted list using the
valueProvider
function that produces
character values as base for sorting.
-
sumBy(int selector(T))
→ int
-
Returns the sum of all values produced by the
selector
function that is
applied to each element.
-
sumByDouble(num selector(T))
→ double
-
Returns the sum of all values produced by the
selector
function that is
applied to each element.
-
withoutFirst()
→ Iterable<T>
-
Lazily returns all values without the first one.
-
withoutLast()
→ Iterable<T>
-
Lazily returns all values without the last one.