IterableX<T> extension
General utility extension on Iterable providing flat-mapping, grouping, and chunking capabilities.
- on
-
- Iterable<
T>
- Iterable<
Properties
- firstOrNull → T?
-
Available on Iterable<
The first element, orT> , provided by the IterableX extensionnullwhen empty.no setter - lastOrNull → T?
-
Available on Iterable<
The last element, orT> , provided by the IterableX extensionnullwhen empty.no setter
Methods
-
associate<
K, V> (MapEntry< K, V> transform(T element)) → Map<K, V> -
Available on Iterable<
Associates each element into a MapEntry returned byT> , provided by the IterableX extensiontransform. -
associateBy<
K> (K keyOf(T element)) → Map< K, T> -
Available on Iterable<
Associates each element by a key derived fromT> , provided by the IterableX extensionkeyOf. -
associateWith<
V> (V valueOf(T element)) → Map< T, V> -
Available on Iterable<
Associates each element with a value derived fromT> , provided by the IterableX extensionvalueOf. -
averageBy(
num selector(T element)) → double? -
Available on Iterable<
Mean ofT> , provided by the IterableX extensionselectorapplied to every element, ornullwhen empty. -
chunked(
int size) → Iterable< List< T> > -
Available on Iterable<
Splits the iterable into chunks ofT> , provided by the IterableX extensionsize. The last chunk may be smaller. -
countWhere(
bool test(T element)) → int -
Available on Iterable<
Number of elements satisfyingT> , provided by the IterableX extensiontest. -
distinctBy<
K> (K keyOf(T)) → Iterable< T> -
Available on Iterable<
Returns distinct elements by a derived key, preserving first-seen order.T> , provided by the IterableX extension -
elementAtOrNull(
int index) → T? -
Available on Iterable<
The element atT> , provided by the IterableX extensionindex, ornullwhen out of range. -
firstWhereOrNull(
bool test(T element)) → T? -
Available on Iterable<
Returns the first element matchingT> , provided by the IterableX extensiontest, ornullif none found. -
flatMap<
R> (Iterable< R> transform(T)) → Iterable<R> -
Available on Iterable<
Maps each element to an iterable, then flattens one level.T> , provided by the IterableX extension -
flatMapNotNull<
R extends Object> (Iterable< R?> transform(T)) → Iterable<R> -
Available on Iterable<
flatMap that discards nulls from the produced iterables.T> , provided by the IterableX extension -
foldIndexed<
R> (R initialValue, R combine(int index, R previous, T element)) → R -
Available on Iterable<
Like Iterable.fold butT> , provided by the IterableX extensioncombinealso receives the index. -
forEachIndexed(
void action(int index, T element)) → void -
Available on Iterable<
Like Iterable.forEach but the action also receives the index.T> , provided by the IterableX extension -
groupBy<
K> (K keyOf(T)) → Map< K, List< T> > -
Available on Iterable<
Groups elements by a key derived fromT> , provided by the IterableX extensionkeyOf. -
intersperse(
T element) → Iterable< T> -
Available on Iterable<
InsertsT> , provided by the IterableX extensionelementbetween every element in this iterable. -
joinToString(
{String separator = ', ', String prefix = '', String suffix = '', String transform(T element)?, int? limit, String truncated = '...'}) → String -
Available on Iterable<
Renders the iterable as a string with fine-grained control.T> , provided by the IterableX extension -
lastWhereOrNull(
bool test(T element)) → T? -
Available on Iterable<
Returns the last element matchingT> , provided by the IterableX extensiontest, ornullif none found. -
mapIndexed<
R> (R transform(int index, T element)) → Iterable< R> -
Available on Iterable<
Like Iterable.map but the transform also receives the index.T> , provided by the IterableX extension -
mapNotNull<
R extends Object> (R? transform(T element)) → Iterable< R> -
Available on Iterable<
Maps each element and drops theT> , provided by the IterableX extensionnullresults. -
maxBy(
Comparable< Object?> selector(T element)) → T? -
Available on Iterable<
The element with the largestT> , provided by the IterableX extensionselectorkey, ornullwhen empty. -
minBy(
Comparable< Object?> selector(T element)) → T? -
Available on Iterable<
The element with the smallestT> , provided by the IterableX extensionselectorkey, ornullwhen empty. -
none(
bool test(T element)) → bool -
Available on Iterable<
Whether no element satisfiesT> , provided by the IterableX extensiontest. The inverse of Iterable.any. -
partition(
bool predicate(T element)) → (List< T> , List<T> ) -
Available on Iterable<
Splits elements into a pair of lists:T> , provided by the IterableX extension(matching, nonMatching). -
randomOrNull(
[Random? random]) → T? -
Available on Iterable<
A uniformly random element, orT> , provided by the IterableX extensionnullwhen empty. -
singleWhereOrNull(
bool test(T element)) → T? -
Available on Iterable<
Returns the single element matchingT> , provided by the IterableX extensiontest, ornullif zero or more than one match. -
sortedBy(
Comparable< Object?> selector(T element)) → List<T> -
Available on Iterable<
A new list sorted ascending by the key returned fromT> , provided by the IterableX extensionselector. -
sortedByDescending(
Comparable< Object?> selector(T element)) → List<T> -
Available on Iterable<
A new list sorted descending by the key returned fromT> , provided by the IterableX extensionselector. -
sortedWith(
Comparator< T> compare) → List<T> -
Available on Iterable<
A new list sorted withT> , provided by the IterableX extensioncompare, leaving this iterable untouched. -
splitWhen(
bool shouldSplit(T previous, T current)) → Iterable< List< T> > -
Available on Iterable<
Splits into runs, starting a new run wheneverT> , provided by the IterableX extensionshouldSplitreturnstruefor a consecutive pair. -
sumBy(
num selector(T element)) → num -
Available on Iterable<
Sum ofT> , provided by the IterableX extensionselectorapplied to every element. Returns0when empty. -
takeWhileInclusive(
bool predicate(T element)) → Iterable< T> -
Available on Iterable<
Yields elements whileT> , provided by the IterableX extensionpredicateholds, plus the first element that failspredicate. -
whereIndexed(
bool test(int index, T element)) → Iterable< T> -
Available on Iterable<
Like Iterable.where but the test also receives the index.T> , provided by the IterableX extension -
whereNot(
bool test(T element)) → Iterable< T> -
Available on Iterable<
Elements that do not satisfyT> , provided by the IterableX extensiontest. -
windowed(
int size, {int step = 1, bool partial = false}) → Iterable< List< T> > -
Available on Iterable<
Returns a sliding window of elements of sizeT> , provided by the IterableX extensionsize. -
zip<
R> (Iterable< R> other) → Iterable<(T, R)> -
Available on Iterable<
Pairs elements positionally withT> , provided by the IterableX extensionother, stopping at the shorter one. -
zipWith<
R, V> (Iterable< R> other, V combine(T a, R b)) → Iterable<V> -
Available on Iterable<
Combines elements positionally withT> , provided by the IterableX extensionotherviacombine.