IterableUtils<T> extension
Extensions on Iterable for real-world utility operations.
These work on any Iterable — List, Set, generator sequences, etc.
- on
-
- Iterable<
T>
- Iterable<
Properties
- firstOrNull → T?
-
Available on Iterable<
Returns the first element, orT> , provided by the IterableUtils extensionnullif the iterable is empty.no setter - lastOrNull → T?
-
Available on Iterable<
Returns the last element, orT> , provided by the IterableUtils extensionnullif the iterable is empty.no setter - singleOrNull → T?
-
Available on Iterable<
Returns the single element, orT> , provided by the IterableUtils extensionnullif empty or has more than one.no setter
Methods
-
associateBy<
K> (K key(T)) → Map< K, T> -
Available on Iterable<
Indexes elements byT> , provided by the IterableUtils extensionkey, returning aMap<K, T>. If multiple elements share a key, the last one wins. -
associateWith<
V> (V value(T)) → Map< T, V> -
Available on Iterable<
Returns a map of each element to the result ofT> , provided by the IterableUtils extensionvalue. -
averageBy(
num f(T)) → double -
Available on Iterable<
Returns the average ofT> , provided by the IterableUtils extensionfapplied to each element. Returns0if empty. -
chunked(
int size) → Iterable< List< T> > -
Available on Iterable<
Splits the iterable into chunks ofT> , provided by the IterableUtils extensionsize. -
count(
bool predicate(T)) → int -
Available on Iterable<
Returns the number of elements satisfyingT> , provided by the IterableUtils extensionpredicate. -
distinctBy<
K> (K key(T)) → Iterable< T> -
Available on Iterable<
Returns distinct elements byT> , provided by the IterableUtils extensionkey. -
flatMap<
R> (Iterable< R> f(T)) → Iterable<R> -
Available on Iterable<
Maps each element to an Iterable and flattens the result.T> , provided by the IterableUtils extension -
forEachIndexed(
void f(int index, T element)) → void -
Available on Iterable<
CallsT> , provided by the IterableUtils extensionffor each element with its index. -
groupBy<
K> (K key(T)) → Map< K, List< T> > -
Available on Iterable<
Groups elements byT> , provided by the IterableUtils extensionkey, returning aMap<K, List<T>>. -
mapIndexed<
R> (R f(int index, T element)) → Iterable< R> -
Available on Iterable<
Maps each element with its index.T> , provided by the IterableUtils extension -
maxBy<
R extends Comparable> (R f(T)) → T? -
Available on Iterable<
Returns the element with the maximum value ofT> , provided by the IterableUtils extensionf, ornullif empty. -
minBy<
R extends Comparable> (R f(T)) → T? -
Available on Iterable<
Returns the element with the minimum value ofT> , provided by the IterableUtils extensionf, ornullif empty. -
none(
bool predicate(T)) → bool -
Available on Iterable<
ReturnsT> , provided by the IterableUtils extensiontrueif no elements satisfypredicate. -
sumBy(
num f(T)) → num -
Available on Iterable<
Returns the sum ofT> , provided by the IterableUtils extensionfapplied to each element. -
whereIndexed(
bool f(int index, T element)) → Iterable< T> -
Available on Iterable<
Filters elements with their index.T> , provided by the IterableUtils extension