KtIterableExtensions<T> extension

on

Properties

dart Iterable<T>
Returns a dart:core Iterable
no setter

Methods

all(bool predicate(T element)) bool
Returns true if all elements match the given predicate.
any([bool predicate(T element)?]) bool
Returns true if at least one element matches the given predicate.
asIterable() KtIterable<T>
Returns this collection as an Iterable.
associate<K, V>(KtPair<K, V> transform(T)) KtMap<K, V>
Returns a Map containing key-value pairs provided by transform function applied to elements of the given collection.
associateBy<K>(K keySelector(T)) KtMap<K, T>
Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.
associateByTo<K, V, M extends KtMutableMap<K, V>>(M destination, K keySelector(T), [V valueTransform(T)?]) → M
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given collection.
associateByTransform<K, V>(K keySelector(T), V valueTransform(T)) KtMap<K, V>
Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element. The element can be transformed with valueTransform.
associateTo<K, V, M extends KtMutableMap<K, V>>(M destination, KtPair<K, V> transform(T)) → M
Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given collection.
associateWith<V>(V valueSelector(T)) KtMap<T, V>
Returns a Map where keys are elements from the given collection and values are produced by the valueSelector function applied to each element.
associateWithTo<V, M extends KtMutableMap>(M destination, V valueSelector(T)) → M
Populates and returns the destination mutable map with key-value pairs for each element of the given collection, where key is the element itself and value is provided by the valueSelector function applied to that key.
averageBy(num selector(T)) double
Returns an average value produced by selector function applied to each element in the collection.
cast<R>() KtIterable<R>
Provides a view of this KtIterable as an iterable of R instances.
chunked(int size) KtList<KtList<T>>
Splits this collection into a list of lists each not exceeding the given size.
chunkedTransform<R>(int size, R transform(KtList<T>)) KtList<R>
Splits this collection into several lists each not exceeding the given size and applies the given transform function to an each.
contains(T element) bool
Returns true if element is found in the collection.
count([bool predicate(T)?]) int
Returns the number of elements matching the given predicate or the number of elements when predicate = null.
distinct() KtList<T>
Returns a list containing only distinct elements from the given collection.
distinctBy<K>(K selector(T)) KtList<T>
Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.
drop(int n) KtList<T>
Returns a list containing all elements except first n elements.
dropWhile(bool predicate(T)) KtList<T>
Returns a list containing all elements except first elements that satisfy the given predicate.
elementAt(int index) → T
Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this collection.
elementAtOrElse(int index, T defaultValue(int)) → T
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) → T?
Returns an element at the given index or null if the index is out of bounds of this collection.
filter(bool predicate(T)) KtList<T>
Returns a list containing only elements matching the given predicate.
filterIndexed(bool predicate(int index, T)) KtList<T>
Returns a list containing only elements matching the given predicate. @param predicate function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
filterIndexedTo<C extends KtMutableCollection>(C destination, bool predicate(int index, T)) → C
Appends all elements matching the given predicate to the given destination. @param predicate function that takes the index of an element and the element itself and returns the result of predicate evaluation on the element.
filterIsInstance<R>() KtList<R>
Returns a list containing all elements that are instances of specified type parameter R.
filterNot(bool predicate(T)) KtList<T>
Returns a list containing all elements not matching the given predicate.
filterNotTo<C extends KtMutableCollection>(C destination, bool predicate(T)) → C
Appends all elements not matching the given predicate to the given destination.
filterTo<C extends KtMutableCollection>(C destination, bool predicate(T)) → C
Appends all elements matching the given predicate to the given destination.
find(bool predicate(T)) → T?
Returns the first element matching the given predicate, or null if no such element was found.
findLast(bool predicate(T)) → T?
Returns the last element matching the given predicate, or null if no such element was found.
first([bool predicate(T)?]) → T
Returns first element.
firstOrNull([bool predicate(T)?]) → T?
Returns the first element (matching predicate when provided), or null if the collection is empty.
flatMap<R>(KtIterable<R> transform(T)) KtList<R>
Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.
flatMapIndexed<R>(KtIterable<R> transform(int index, T)) KtList<R>
Returns a single list of all elements yielded from results of transform function being invoked on each element and its index in the original collection.
flatMapIndexedTo<R, C extends KtMutableCollection<R>>(C destination, KtIterable<R> transform(int index, T)) → C
Appends all elements yielded from results of transform function being invoked on each element and its index in the original collection, to the given destination.
flatMapTo<R, C extends KtMutableCollection<R>>(C destination, KtIterable<R> transform(T)) → C
Appends all elements yielded from results of transform function being invoked on each element of original collection, to the given destination.
fold<R>(R initial, R operation(R acc, T)) → R
Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.
foldIndexed<R>(R initial, R operation(int index, R acc, T)) → R
Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element with its index in the original collection. @param operation function that takes the index of an element, current accumulator value and the element itself, and calculates the next accumulator value.
forEach(void action(T element)) → void
Performs the given action on each element.
forEachIndexed(void action(int index, T element)) → void
Performs the given action on each element, providing sequential index with the element. @param action function that takes the index of an element and the element itself and performs the desired action on the element.
groupBy<K>(K keySelector(T)) KtMap<K, KtList<T>>
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 list of corresponding elements.
groupByTo<K, M extends KtMutableMap<K, KtMutableList>>(M destination, K keySelector(T)) → M
Groups elements of the original collection by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
groupByToTransform<K, V, M extends KtMutableMap<K, KtMutableList<V>>>(M destination, K keySelector(T), V valueTransform(T)) → M
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 puts to the destination map each group key associated with a list of corresponding values.
groupByTransform<K, V>(K keySelector(T), V valueTransform(T)) KtMap<K, KtList<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 list of corresponding values.
indexOf(T element) int
Returns first index of element, or -1 if the collection does not contain element.
indexOfFirst(bool predicate(T)) int
Returns index of the first element matching the given predicate, or -1 if the collection does not contain such element.
indexOfLast(bool predicate(T)) int
Returns index of the last element matching the given predicate, or -1 if the collection does not contain such element.
intersect(KtIterable<T> other) KtSet<T>
Returns a set containing all elements that are contained by both this set and the specified collection.
joinToString({String separator = ", ", String prefix = "", String postfix = "", int limit = -1, String truncated = "...", String transform(T)?}) String
Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.
last([bool predicate(T)?]) → T
Returns the last element matching the given predicate. @throws NoSuchElementException if no such element is found.
lastIndexOf(T element) int
Returns last index of element, or -1 if the collection does not contain element.
lastOrNull([bool predicate(T)?]) → T?
Returns the last element matching the given predicate, or null if no such element was found.
map<R>(R transform(T)) KtList<R>
Returns a list containing the results of applying the given transform function to each element in the original collection.
mapIndexed<R>(R transform(int index, T)) KtList<R>
Returns a list containing the results of applying the given transform function to each element and its index in the original collection. @param transform function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
mapIndexedTo<R, C extends KtMutableCollection<R>>(C destination, R transform(int index, T)) → C
Applies the given transform function to each element and its index in the original collection and appends the results to the given destination. @param transform function that takes the index of an element and the element itself and returns the result of the transform applied to the element.
mapTo<R, C extends KtMutableCollection<R>>(C destination, R transform(T)) → C
Applies the given transform function to each element of the original collection and appends the results to the given destination.
maxBy<R extends Comparable>(R selector(T)) → T?
Returns the first element yielding the largest value of the given function or null if there are no elements.
maxOf<R extends Comparable>(R selector(T)) → R
Returns the largest value among all values produced by selector function applied to each element in the collection.
maxWith(Comparator<T> comparator) → T?
Returns the first element having the largest value according to the provided comparator or null if there are no elements.
minBy<R extends Comparable>(R selector(T)) → T?
Returns the first element yielding the smallest value of the given function or null if there are no elements.
minOf<R extends Comparable>(R selector(T)) → R
Returns the smallest value among all values produced by selector function applied to each element in the array.
minus(KtIterable<T> elements) KtList<T>
Returns a list containing all elements of the original collection except the elements contained in the given elements collection.
minusElement(T element) KtList<T>
Returns a list containing all elements of the original collection without the first occurrence of the given element.
minWith(Comparator<T> comparator) → T?
Returns the first element having the smallest value according to the provided comparator or null if there are no elements.
none([bool predicate(T)?]) bool
Returns true if the collection has no elements or no elements match the given predicate.
partition(bool predicate(T)) KtPair<KtList<T>, KtList<T>>
Splits the original collection into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false.
plus(KtIterable<T> elements) KtList<T>
Returns a list containing all elements of the original collection and then all elements of the given elements collection.
plusElement(T element) KtList<T>
Returns a list containing all elements of the original collection and then the given element.
reduce<S>(S operation(S acc, T)) → S
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.
reduceIndexed<S>(S operation(int index, S acc, T)) → S
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original collection. @param operation function that takes the index of an element, current accumulator value and the element itself and calculates the next accumulator value.
reduceIndexedOrNull<S>(S operation(int index, S acc, T)) → S?
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original collection.
reduceOrNull<S>(S operation(S acc, T)) → S?
Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.
reversed() KtList<T>
Returns a list with elements in reversed order.
runningReduce<S>(S operation(S acc, T)) KtList<S>
Returns a list containing successive accumulation values generated by applying operation from left to right to each element and current accumulator value that starts with the first element of this collection.
runningReduceIndexed<S>(S operation(int index, S acc, T)) KtList<S>
Returns a list containing successive accumulation values generated by applying operation 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]) KtList<T>
Returns a new list with the elements of this list randomly shuffled.
single([bool predicate(T)?]) → T
Returns the single element matching the given predicate, or throws an exception if the list is empty or has more than one element.
singleOrNull([bool predicate(T)?]) → T?
Returns the single element matching the given predicate, or null if element was not found or more than one element was found.
sorted() KtList<T>
Returns a list of all elements sorted according to their natural sort order.
sortedBy<R extends Comparable>(R selector(T)) KtList<T>
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(T)) KtList<T>
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
sortedDescending() KtList<T>
Returns a list of all elements sorted descending according to their natural sort order.
sortedWith(Comparator<T> comparator) KtList<T>
Returns a list of all elements sorted according to the specified comparator.
subtract(KtIterable<T> other) KtSet<T>
Returns a set containing all elements that are contained by this collection and not contained by the specified collection.
sumBy<R extends num>(R selector(T)) → R
Returns the sum of all values produced by selector function applied to each element in the collection.
sumByDouble(double selector(T)) double
Returns the sum of all values produced by selector function applied to each element in the collection.
take(int n) KtList<T>
Returns a list containing first n elements.
takeWhile(bool predicate(T)) KtList<T>
Returns a list containing first elements satisfying the given predicate.
toCollection<C extends KtMutableCollection>(C destination) → C
Appends all elements to the given destination collection.
toHashSet() KtMutableSet<T>
Returns a HashSet of all elements.
toList() KtList<T>
Returns a KtList containing all elements.
toMutableList() KtMutableList<T>
Returns a KtMutableList filled with all elements of this collection.
toMutableSet() KtMutableSet<T>
Returns a mutable set containing all distinct elements from the given collection.
toSet() KtSet<T>
Returns a KtSet of all elements.
union(KtIterable<T> other) KtSet<T>
Returns a set containing all distinct elements from both collections.
windowed(int size, {int step = 1, bool partialWindows = false}) KtList<KtList<T>>
Returns a list of snapshots of the window of the given size sliding along this collection with the given step, where each snapshot is a list.
windowedTransform<R>(int size, R transform(KtList<T>), {int step = 1, bool partialWindows = false}) KtList<R>
Returns a list of results of applying the given transform function to an each list representing a view over the window of the given size sliding along this collection with the given step.
zip<R>(KtIterable<R> other) KtList<KtPair<T, R>>
Returns a list of pairs built from the elements of this collection and other collection with the same index. The returned list has length of the shortest collection.
zipTransform<R, V>(KtIterable<R> other, V transform(T a, R b)) KtList<V>
Returns a list 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 list has length of the shortest collection.
zipWithNext() KtList<KtPair<T, T>>
Returns a list of pairs of each two adjacent elements in this collection.
zipWithNextTransform<R>(R transform(T a, T b)) KtList<R>
Returns a list containing the results of applying the given transform function to an each pair of two adjacent elements in this collection.

Operators

operator +(KtIterable<T> elements) KtList<T>
Returns a list containing all elements of the original collection and then all elements of the given elements collection.
operator -(KtIterable<T> elements) KtList<T>
Returns a list containing all elements of the original collection except the elements contained in the given elements collection.