KtcIterable<E> extension

on

Properties

distinct Iterable<E>
Returns a Iterable containing only distinct elements from the given collection.
no setter
firstOrNull → E?
Returns the first element, or null if the collection is empty.
no setter
indices Iterable<int>
Returns an Iterable of the valid indices for this collection.
no setter
lastOrNull → E?
Returns the last element, or null if the collection is empty.
no setter
reversed Iterable<E>
Returns a Iterable with elements in reversed order.
no setter
singleOrNull → E?
Returns single element, or null if the collection is empty or has more than one element.
no setter
withIndex Iterable<IndexedValue<E>>
Returns a lazy Iterable that wraps each element of the original collection into an IndexedValue containing the index of that element and the element itself.
no setter
zipWithNext Iterable<Pair<E, E>>
Returns a Iterable of pairs of each two adjacent elements in this collection.
no setter

Methods

associate<K, V>(MapEntry<K, V> transfrom(E element)) Map<K, V>
Returns a Map containing MapEntrys provided by transform function applied to elements of the given collection.
associateAndTransformBy<K, V>(K keySelector(E element), V valueTransform(E element)) Map<K, V>
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given collection.
associateBy<K>(K keySelector(E element)) Map<K, E>
Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.
associateWith<V>(V valueSelector(E element)) Map<E, V>
Returns a Map where keys are elements from the given collection and values are produced by the valueSelector function applied to each element.
chunked(int size) Iterable<Iterable<E>>
Splits this collection into a Iterable of iterables each not exceeding the given size.
chunkedAndTransform<T>(int size, T transform(Iterable<E> chunk)) Iterable<T>
Splits this collection into several iterables each not exceeding the given size and applies the given transform function to an each.
containsAll(Iterable<E> other) bool
Checks if all elements in the specified collection are contained in this collection.
count([bool test(E element)?]) int
Returns the number of elements passing the given test. If test is not provided it returns the number of elements in the Iterable.
distinctBy<K>(K selector(E element)) Iterable<E>
Returns a Iterable containing only elements from the given collection having distinct keys returned by the given selector function.
elementAtOrElse(int index, E defaultValue(int index)) → E
Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this collection.
elementAtOrNull(int index) → E?
Returns an element at the given index or null if the index is out of bounds of this collection.
expandIndexed<T>(Iterable<T> transform(int index, E element)) Iterable<T>
Returns a single Iterable of all elements yielded from results of transform function being invoked on each element and its index in the original collection.
firstNotNullOf<T>(T? transform(E element)) → T
Returns the first non-null value produced by transform function being applied to elements of this collection in iteration order, or throws NoSuchElementException if no non-null value was produced.
firstNotNullOfOrNull<T>(T? transform(E element)) → T?
Returns the first non-null value produced by transform function being applied to elements of this collection in iteration order, or null if no non-null value was produced.
firstWhereOrNull(bool test(E element)) → E?
Returns the first element passing the given test, or null if no such element was found.
flatMap<R>(Iterable<R> transform(E element)) Iterable<R>
Returns a single Iterable of all elements yielded from results of transform function being invoked on each element of original collection.
flatMapIndexed<R>(Iterable<R> transform(int index, E element)) Iterable<R>
Returns a single Iterable of all elements yielded from results of transform function being invoked on each element and its index in the original collection.
foldIndexed<T>(T initialValue, T combine(int index, T previousValue, E element)) → T
Accumulates value starting with initialValue and applying operation from left to right to current accumulator value and each element with its index in the original collection.
forEachIndexed(void action(int index, E element)) → void
Performs the given action on each element, providing sequential index with the element.
groupAndTransformBy<K, V>(K keySelector(E element), V valueTransform(E element)) Map<K, Iterable<V>>
Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and returns a Map where each group key is associated with a Iterable of corresponding values.
groupBy<K>(K keySelector(E element)) Map<K, Iterable<E>>
Groups elements of the original collection by the key returned by the given keySelector function applied to each element and returns a Map where each group key is associated with a Iterable of corresponding elements.
indexOf(E element) int
Returns first index of element, or -1 if the collection does not contain element.
indexOfFirst(bool test(E element)) int
Returns index of the first element passing the given test, or -1 if the collection does not contain such element.
indexOfLast(bool test(E element)) int
Returns index of the last element passing the given test, or -1 if the collection does not contain such element.
intersect(Iterable<E> other) Iterable<E>
Returns a Iterable containing all elements that are contained by both this collection and the specified collection.
joinTo<S extends StringSink>({required S buffer, Object separator = ', ', Object prefix = '', Object postfix = '', int limit = -1, Object truncated = '...', Object transform(E element)?}) → S
Appends the String from all the elements separated using separator and using the given prefix and postfix if supplied.
joinToString({Object separator = ', ', Object prefix = '', Object postfix = '', int limit = -1, Object truncated = '...', Object transform(E element)?}) String
Creates a String from all the elements separated using separator and using the given prefix and postfix if supplied.
lastIndexOf(E element) int
Returns last index of element, or -1 if the collection does not contain element.
lastWhereOrNull(bool test(E element)) → E?
Returns the last element passing the given test, or null if no such element was found.
mapIndexed<R>(R transform(int index, E element)) Iterable<R>
Returns an Iterable containing the results of applying the given transform function to each element and its index in the original collection.
mapIndexedNotNull<R>(R? transform(int index, E element)) Iterable<R>
Returns an Iterable containing only the non-null results of applying the given transform function to each element and its index in the original collection.
mapNotNull<R>(R? transform(E element)) Iterable<R>
Returns an Iterable containing only the non-null results of applying the given transform function to each element in the original collection.
maxByOrNull<R extends Comparable>(R selector(E element)) → E?
Returns the first element yielding the largest value of the given selector or null if there are no elements.
maxOf<R extends Comparable>(R selector(E element)) → R
Returns the largest value among all values produced by selector function applied to each element in the collection.
maxOfOrNull<R extends Comparable>(R selector(E element)) → R?
Returns the largest value among all values produced by selector function applied to each element in the collection or null if there are no elements.
maxOfWith<R>(Comparator<R> comparator, R selector(E element)) → R
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection.
maxOfWithOrNull<R>(Comparator<R> comparator, R selector(E element)) → R?
Returns the largest value according to the provided comparator among all values produced by selector function applied to each element in the collection or null if there are no elements.
maxWithOrNull(Comparator<E> comparator) → E?
Returns the first element having the largest value according to the provided comparator or null if there are no elements.
minByOrNull<R extends Comparable>(R selector(E element)) → E?
Returns the first element yielding the smallest value of the given selector function or null if there are no elements.
minOf<R extends Comparable>(R selector(E element)) → R
Returns the smallest value among all values produced by selector function applied to each element in the collection.
minOfOrNull<R extends Comparable>(R selector(E element)) → R?
Returns the smallest value among all values produced by selector function applied to each element in the collection or null if there are no elements.
minOfWith<R>(Comparator<R> comparator, R selector(E element)) → R
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection.
minOfWithOrNull<R>(Comparator<R> comparator, R selector(E element)) → R?
Returns the smallest value according to the provided comparator among all values produced by selector function applied to each element in the collection or null if there are no elements.
minWithOrNull(Comparator<E> comparator) → E?
Returns the first element having the smallest value according to the provided comparator or null if there are no elements.
none([bool test(E element)?]) bool
Returns true if the collection has no elements.
onEach(void action(E element)) Iterable<E>
Performs the given action on each element and returns the collection itself afterwards.
onEachIndexed(void action(int index, E element)) Iterable<E>
Performs the given action on each element, providing sequential index with the element, and returns the collection itself afterwards.
partition(bool test(E element)) Pair<Iterable<E>, Iterable<E>>
Splits the original collection into Pair of iterables, where first Iterable contains elements for which test yielded true, while second Iterable contains elements for which test yielded false.
reduceIndexed(E combine(int index, E value, E element)) → E
Accumulates value starting with the first element and applying combine function from left to right to current accumulator value and each element with its index in the original collection.
reduceIndexedOrNull(E combine(int index, E value, E element)) → E?
Accumulates value starting with the first element and applying combine function from left to right to current accumulator value and each element with its index in the original collection.
reduceOrNull(E combine(E value, E element)) → E?
Accumulates value starting with the first element and applying combine function from left to right to current accumulator value and each element.
runningFold<R>(R initialValue, R combine(R previousValue, E element)) Iterable<R>
Returns a Iterable containing successive accumulation values generated by applying combine function from left to right to each element and current accumulator value that starts with initialValue.
runningFoldIndexed<R>(R initialValue, R combine(int index, R previousValue, E element)) Iterable<R>
Returns a Iterable containing successive accumulation values generated by applying combine function from left to right to each element and current accumulator value that starts with initialValue.
runningReduce(E combine(E value, E element)) Iterable<E>
Returns a Iterable containing successive accumulation values generated by applying combine function from left to right to each element and current accumulator value that starts with the first element of this collection.
runningReduceIndexed(E combine(int index, E value, E element)) Iterable<E>
Returns a Iterable containing successive accumulation values generated by applying combine function from left to right to each element, its index in the original collection and current accumulator value that starts with the first element of this collection.
shuffled([Random? random]) List<E>
Returns a new List with the elements of this list randomly shuffled using the specified random instance as the source of randomness.
singleWhereOrNull(bool test(E element)) → E?
Returns the single element passing the given test, or null if element was not found or more than one element was found.
sortedBy<R extends Comparable>(R selector(E element)) List<E>
Returns a List of all elements sorted according to natural sort order of the value returned by specified selector function.
sortedByDescending<R extends Comparable>(R selector(E element)) List<E>
Returns a List of all elements sorted descending according to natural sort order of the value returned by specified selector function.
sortedWith(Comparator<E> comparator) List<E>
Returns a List of all elements sorted according to the specified comparator.
union(Iterable<E> other) Iterable<E>
Returns a Iterable containing all distinct elements from both collections.
whereIndexed(bool test(int index, E element)) Iterable<E>
Returns a Iterable containing only elements passing the given test.
whereIsInstance<T>() Iterable<T>
Returns an Iterable containing all elements that are instances of specified type parameter T.
whereNot(bool test(E element)) Iterable<E>
Returns an Iterable containing all elements not passing the given test.
windowed({required int size, int step = 1, bool partialWindows = false}) Iterable<Iterable<E>>
Returns a Iterable of snapshots of the window of the given size sliding along this collection with the given step, where each snapshot is a Iterable.
windowedAndTransform<R>({required int size, required R transform(Iterable<E> chunk), int step = 1, bool partialWindows = false}) Iterable<R>
Returns a Iterable of results of applying the given transform function to an each Iterable representing a view over the window of the given size sliding along this collection with the given step.
zip<T>(Iterable<T> other) Iterable<Pair<E, T>>
Returns a Iterable of pairs built from the elements of this collection and other collection with the same index. The returned Iterable has length of the shortest collection.
zipAndTransform<T, R>(Iterable<T> other, R transform(Pair<E, T> pair)) Iterable<R>
Returns a Iterable of values built from the elements of this collection and the other collection with the same index using the provided transform function applied to each pair of elements. The returned Iterable has length of the shortest collection.
zipWithNextAndTransform<R>(R transform(Pair<E, E> pair)) Iterable<R>
Returns a Iterable containing the results of applying the given transform function to an each Pair of two adjacent elements in this collection.

Operators

operator &(Iterable<E> other) Iterable<E>
Returns a Iterable containing all elements that are contained by both this collection and the specified collection.
operator +(Iterable<E> other) Iterable<E>
Returns an Iterable containing all elements of the original collection and then all elements of the other collection.
operator -(Iterable<E> other) Iterable<E>
Returns an Iterable containing all elements of the original collection except the elements contained in the other collection.
operator <<(int count) Iterable<E>
Returns an Iterable that has been removed by the number of count from the beginning.
operator >>(int count) Iterable<E>
Returns an Iterable that has been removed by the number of count from the end.
operator ^(Iterable<E> other) Iterable<E>
Returns a Iterable containing all elements from both collections without intersect.
operator |(Iterable<E> other) Iterable<E>
Returns a Iterable containing all distinct elements from both collections.