IterableExtension<T> extension

Extensions that apply to all iterables.

These extensions provide direct access to some of the algorithms expose by this package, as well as some generally useful convenience methods.

More specialized extension methods that only apply to iterables with specific element types include those of IterableComparableExtension and IterableNullableExtension.

on

Properties

firstOrNull → T?
The first element, or null if the iterable is empty.
no setter
lastOrNull → T?
The last element, or null if the iterable is empty.
no setter
singleOrNull → T?
The single element of the iterable, or null.
no setter

Methods

elementAtOrNull(int index) → T?
The indexth element, or null if there is no such element.
expandIndexed<R>(Iterable<R> expand(int index, T element)) Iterable<R>
Expands each element and index to a number of elements in a new iterable.
firstWhereIndexedOrNull(bool test(int index, T element)) → T?
The first element whose value and index satisfies test.
firstWhereOrNull(bool test(T element)) → T?
The first element satisfying test, or null if there are none.
foldIndexed<R>(R initialValue, R combine(int index, R previous, T element)) → R
Combine the elements with a value and the current index.
forEachIndexed(void action(int index, T element)) → void
Takes an action for each element.
forEachIndexedWhile(bool action(int index, T element)) → void
Takes an action for each element and index as long as desired.
forEachWhile(bool action(T element)) → void
Takes an action for each element as long as desired.
groupFoldBy<K, G>(K keyOf(T element), G combine(G? previous, T element)) Map<K, G>
Groups elements by keyOf then folds the elements in each group.
groupListsBy<K>(K keyOf(T element)) Map<K, List<T>>
Groups elements into lists by keyOf.
groupSetsBy<K>(K keyOf(T element)) Map<K, Set<T>>
Groups elements into sets by keyOf.
isSorted(Comparator<T> compare) bool
Whether the elements are sorted by the compare ordering.
isSortedBy<K extends Comparable<K>>(K keyOf(T element)) bool
Whether the elements are sorted by their keyOf property.
isSortedByCompare<K>(K keyOf(T element), Comparator<K> compare) bool
Whether the elements are compare-sorted by their keyOf property.
lastBy<K>(K key(T)) Map<K, T>
Associates the elements in this by the value returned by key.
lastWhereIndexedOrNull(bool test(int index, T element)) → T?
The last element whose index and value satisfies test.
lastWhereOrNull(bool test(T element)) → T?
The last element satisfying test, or null if there are none.
mapIndexed<R>(R convert(int index, T element)) Iterable<R>
Maps each element and its index to a new value.
none(bool test(T)) bool
Whether no element satisfies test.
reduceIndexed(T combine(int index, T previous, T element)) → T
Combine the elements with each other and the current index.
sample(int count, [Random? random]) List<T>
Selects count elements at random from this iterable.
shuffled([Random? random]) List<T>
Creates a shuffled list of the elements of the iterable.
singleWhereIndexedOrNull(bool test(int index, T element)) → T?
The single element satisfying test.
singleWhereOrNull(bool test(T element)) → T?
The single element satisfying test.
slices(int length) Iterable<List<T>>
Contiguous slices of this with the given length.
sorted(Comparator<T> compare) List<T>
Creates a sorted list of the elements of the iterable.
sortedBy<K extends Comparable<K>>(K keyOf(T element)) List<T>
Creates a sorted list of the elements of the iterable.
sortedByCompare<K>(K keyOf(T element), Comparator<K> compare) List<T>
Creates a sorted list of the elements of the iterable.
splitAfter(bool test(T element)) Iterable<List<T>>
Splits the elements into chunks after some elements.
splitAfterIndexed(bool test(int index, T element)) Iterable<List<T>>
Splits the elements into chunks after some elements and indices.
splitBefore(bool test(T element)) Iterable<List<T>>
Splits the elements into chunks before some elements.
splitBeforeIndexed(bool test(int index, T element)) Iterable<List<T>>
Splits the elements into chunks before some elements and indices.
splitBetween(bool test(T first, T second)) Iterable<List<T>>
Splits the elements into chunks between some elements.
splitBetweenIndexed(bool test(int index, T first, T second)) Iterable<List<T>>
Splits the elements into chunks between some elements and indices.
whereIndexed(bool test(int index, T element)) Iterable<T>
The elements whose value and index satisfies test.
whereNot(bool test(T element)) Iterable<T>
The elements that do not satisfy test.
whereNotIndexed(bool test(int index, T element)) Iterable<T>
The elements whose value and index do not satisfy test.