IterableX<T> extension

General utility extension on Iterable providing flat-mapping, grouping, and chunking capabilities.

on

Properties

firstOrNull → T?

Available on Iterable<T>, provided by the IterableX extension

The first element, or null when empty.
no setter
lastOrNull → T?

Available on Iterable<T>, provided by the IterableX extension

The last element, or null when empty.
no setter

Methods

associate<K, V>(MapEntry<K, V> transform(T element)) → Map<K, V>

Available on Iterable<T>, provided by the IterableX extension

Associates each element into a MapEntry returned by transform.
associateBy<K>(K keyOf(T element)) → Map<K, T>

Available on Iterable<T>, provided by the IterableX extension

Associates each element by a key derived from keyOf.
associateWith<V>(V valueOf(T element)) → Map<T, V>

Available on Iterable<T>, provided by the IterableX extension

Associates each element with a value derived from valueOf.
averageBy(num selector(T element)) → double?

Available on Iterable<T>, provided by the IterableX extension

Mean of selector applied to every element, or null when empty.
chunked(int size) → Iterable<List<T>>

Available on Iterable<T>, provided by the IterableX extension

Splits the iterable into chunks of size. The last chunk may be smaller.
countWhere(bool test(T element)) → int

Available on Iterable<T>, provided by the IterableX extension

Number of elements satisfying test.
distinctBy<K>(K keyOf(T)) → Iterable<T>

Available on Iterable<T>, provided by the IterableX extension

Returns distinct elements by a derived key, preserving first-seen order.
elementAtOrNull(int index) → T?

Available on Iterable<T>, provided by the IterableX extension

The element at index, or null when out of range.
firstWhereOrNull(bool test(T element)) → T?

Available on Iterable<T>, provided by the IterableX extension

Returns the first element matching test, or null if none found.
flatMap<R>(Iterable<R> transform(T)) → Iterable<R>

Available on Iterable<T>, provided by the IterableX extension

Maps each element to an iterable, then flattens one level.
flatMapNotNull<R extends Object>(Iterable<R?> transform(T)) → Iterable<R>

Available on Iterable<T>, provided by the IterableX extension

flatMap that discards nulls from the produced iterables.
foldIndexed<R>(R initialValue, R combine(int index, R previous, T element)) → R

Available on Iterable<T>, provided by the IterableX extension

Like Iterable.fold but combine also receives the index.
forEachIndexed(void action(int index, T element)) → void

Available on Iterable<T>, provided by the IterableX extension

Like Iterable.forEach but the action also receives the index.
groupBy<K>(K keyOf(T)) → Map<K, List<T>>

Available on Iterable<T>, provided by the IterableX extension

Groups elements by a key derived from keyOf.
intersperse(T element) → Iterable<T>

Available on Iterable<T>, provided by the IterableX extension

Inserts element between every element in this iterable.
joinToString({String separator = ', ', String prefix = '', String suffix = '', String transform(T element)?, int? limit, String truncated = '...'}) → String

Available on Iterable<T>, provided by the IterableX extension

Renders the iterable as a string with fine-grained control.
lastWhereOrNull(bool test(T element)) → T?

Available on Iterable<T>, provided by the IterableX extension

Returns the last element matching test, or null if none found.
mapIndexed<R>(R transform(int index, T element)) → Iterable<R>

Available on Iterable<T>, provided by the IterableX extension

Like Iterable.map but the transform also receives the index.
mapNotNull<R extends Object>(R? transform(T element)) → Iterable<R>

Available on Iterable<T>, provided by the IterableX extension

Maps each element and drops the null results.
maxBy(Comparable<Object?> selector(T element)) → T?

Available on Iterable<T>, provided by the IterableX extension

The element with the largest selector key, or null when empty.
minBy(Comparable<Object?> selector(T element)) → T?

Available on Iterable<T>, provided by the IterableX extension

The element with the smallest selector key, or null when empty.
none(bool test(T element)) → bool

Available on Iterable<T>, provided by the IterableX extension

Whether no element satisfies test. The inverse of Iterable.any.
partition(bool predicate(T element)) → (List<T>, List<T>)

Available on Iterable<T>, provided by the IterableX extension

Splits elements into a pair of lists: (matching, nonMatching).
randomOrNull([Random? random]) → T?

Available on Iterable<T>, provided by the IterableX extension

A uniformly random element, or null when empty.
singleWhereOrNull(bool test(T element)) → T?

Available on Iterable<T>, provided by the IterableX extension

Returns the single element matching test, or null if zero or more than one match.
sortedBy(Comparable<Object?> selector(T element)) → List<T>

Available on Iterable<T>, provided by the IterableX extension

A new list sorted ascending by the key returned from selector.
sortedByDescending(Comparable<Object?> selector(T element)) → List<T>

Available on Iterable<T>, provided by the IterableX extension

A new list sorted descending by the key returned from selector.
sortedWith(Comparator<T> compare) → List<T>

Available on Iterable<T>, provided by the IterableX extension

A new list sorted with compare, leaving this iterable untouched.
splitWhen(bool shouldSplit(T previous, T current)) → Iterable<List<T>>

Available on Iterable<T>, provided by the IterableX extension

Splits into runs, starting a new run whenever shouldSplit returns true for a consecutive pair.
sumBy(num selector(T element)) → num

Available on Iterable<T>, provided by the IterableX extension

Sum of selector applied to every element. Returns 0 when empty.
takeWhileInclusive(bool predicate(T element)) → Iterable<T>

Available on Iterable<T>, provided by the IterableX extension

Yields elements while predicate holds, plus the first element that fails predicate.
whereIndexed(bool test(int index, T element)) → Iterable<T>

Available on Iterable<T>, provided by the IterableX extension

Like Iterable.where but the test also receives the index.
whereNot(bool test(T element)) → Iterable<T>

Available on Iterable<T>, provided by the IterableX extension

Elements that do not satisfy test.
windowed(int size, {int step = 1, bool partial = false}) → Iterable<List<T>>

Available on Iterable<T>, provided by the IterableX extension

Returns a sliding window of elements of size size.
zip<R>(Iterable<R> other) → Iterable<(T, R)>

Available on Iterable<T>, provided by the IterableX extension

Pairs elements positionally with other, stopping at the shorter one.
zipWith<R, V>(Iterable<R> other, V combine(T a, R b)) → Iterable<V>

Available on Iterable<T>, provided by the IterableX extension

Combines elements positionally with other via combine.