ktx<T> extension

on

Methods

associateBy<K>(K keySelector(T)) Map<K, T>
Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given collection.
associateByTo<K>(Map<K, T> destination, K keySelector(T)) Map<K, T>
Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given collection and value is the element itself.
groupBy<K>(K keySelector(T)) Map<K, List<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>(Map<K, List<T>> destination, K keySelector(T)) Map<K, List<T>>
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.
mapIndexed<R>(R transform(int, T)) List<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>(List<R> destination, R transform(int, T)) List<R>
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.
mapNotNull<R>(R? transform(T)) List<R>
Returns a list containing only the non-null results of applying the given transform function to each element in the original collection.
mapNotNullTo<R>(List<R> destination, R? transform(T)) List<R>
Applies the given transform function to each element in the original collection and appends only the non-null results to the given destination.
sortBy<R extends Comparable<Object>>(R selector(T)) List<T>
Sorts elements in the list in-place according to natural sort order of the value returned by specified selector function.
sortByDescending<R extends Comparable<Object>>(R selector(T)) List<T>
Sorts elements in the list in-place descending according to natural sort order of the value returned by specified selector function.
sortTo(List<T> destination, Comparator<T> comparator) List<T>
zip<R, V>(Iterable<R> other, V transform(T, R)) List<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.