Package-level declarations

Functions

Link copied to clipboard

Returns true when every element equals the first one. An empty iterable returns true.

Link copied to clipboard

Returns true if at least one element occurs more than once.

Link copied to clipboard

Returns a map of each element to its index in this iterable.

Link copied to clipboard
fun <T, R> Iterable<T>.cartesianProduct(other: Iterable<R>): List<Pair<T, R>>

Returns every pairing of an element of this iterable with an element of other.

Link copied to clipboard
inline fun <T, K> Iterable<T>.chunkedBy(selector: (T) -> K): List<List<T>>

Splits this iterable into consecutive runs, starting a new run whenever the value of selector changes.

Link copied to clipboard
inline fun <T, K> Iterable<T>.countBy(selector: (T) -> K): Map<K, Int>

Returns a map of each distinct value of selector to the number of elements producing it.

Link copied to clipboard
fun <T> Iterable<T>.duplicates(): Set<T>

Returns the set of elements that occur more than once.

Link copied to clipboard
fun <T> List<T>.endsWith(suffix: List<T>): Boolean

Returns true if this list ends with the elements of suffix in order.

Link copied to clipboard
fun <K : Any, V> Map<K?, V>.filterKeysNotNull(): Map<K, V>

Returns a map containing only the entries whose key is not null, with keys typed as non-null.

Link copied to clipboard
fun <K, V : Any> Map<K, V?>.filterValuesNotNull(): Map<K, V>

Returns a map containing only the entries whose value is not null, with values typed as non-null.

Link copied to clipboard
fun <T> List<T>.fourth(): T

Returns the fourth element.

Link copied to clipboard
fun <T> List<T>.fourthOrNull(): T?

Returns the fourth element, or null if the list has fewer than four elements.

Link copied to clipboard

Returns a map of each distinct element to the number of times it occurs.

Link copied to clipboard
fun <T> List<T>.headAndTail(): Pair<T, List<T>>

Returns the first element paired with a list of the remaining elements.

Link copied to clipboard

Returns the first element paired with the remaining elements, or null if the list is empty.

Link copied to clipboard
fun <T> List<T>.indicesOf(element: T): List<Int>

Returns every index at which element occurs, in ascending order.

Link copied to clipboard
fun <T> List<T>.interleaved(other: List<T>): List<T>

Returns a list alternating elements of this list and other, starting with this list.

Link copied to clipboard
fun <K, V> Map<K, V>.inverted(): Map<V, K>

Returns a map from each value to its key.

Link copied to clipboard
fun <K, V> Map<K, V>.invertedAll(): Map<V, List<K>>

Returns a map from each value to the list of all keys that map to it.

Link copied to clipboard

Returns true if no element occurs more than once.

Link copied to clipboard
inline fun <K, V, R : Any> Map<K, V>.mapKeysNotNull(transform: (Map.Entry<K, V>) -> R?): Map<R, V>

Returns a map with each key replaced by the result of transform, dropping entries where it returns null.

Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToSet(transform: (T) -> R): Set<R>

Returns a set of the results of applying transform to each element.

Link copied to clipboard
inline fun <K, V, R : Any> Map<K, V>.mapValuesNotNull(transform: (Map.Entry<K, V>) -> R?): Map<K, R>

Returns a map with each value replaced by the result of transform, dropping entries where it returns null.

Link copied to clipboard
@JvmName(name = "medianOfInt")
fun List<Int>.median(): Double
@JvmName(name = "medianOfLong")
fun List<Long>.median(): Double

Returns the median of this list.

Link copied to clipboard
@JvmName(name = "medianOrNullOfInt")
fun List<Int>.medianOrNull(): Double?
@JvmName(name = "medianOrNullOfLong")
fun List<Long>.medianOrNull(): Double?

Returns the median of this list, or null if the list is empty.

Link copied to clipboard
inline fun <K, V> Map<K, V>.mergedWith(other: Map<K, V>, resolve: (key: K, current: V, incoming: V) -> V): Map<K, V>

Returns a map combining this map with other, calling resolve for keys present in both.

Link copied to clipboard
inline fun <K, V> MutableMap<K, V>.mergeWith(other: Map<K, V>, resolve: (key: K, current: V, incoming: V) -> V)

Merges other into this map in place, calling resolve for keys present in both.

Link copied to clipboard
fun <T> List<T>.middle(): T

Returns the middle element, or the earlier of the two middle elements for even sizes.

Link copied to clipboard
fun <T> List<T>.middleOrNull(): T?

Returns the middle element, or null when the list is empty. Even sizes use the earlier middle.

Link copied to clipboard

Returns the smallest and largest element as a pair, or null if the receiver is empty.

Link copied to clipboard
fun <T> Iterable<T>.mode(): T?

Returns the most frequent element, or null if the receiver is empty.

Link copied to clipboard
fun <T> MutableList<T>.move(fromIndex: Int, toIndex: Int)

Moves the element at fromIndex so that it sits at toIndex, shifting the elements between them.

Link copied to clipboard
fun <T> List<T>.moved(fromIndex: Int, toIndex: Int): List<T>

Returns a copy of this list with the element at fromIndex moved so that it sits at toIndex in the result.

Link copied to clipboard
fun <T> List<T>.padded(size: Int, element: T): List<T>

Returns a copy of this list grown to size elements by appending element.

Link copied to clipboard
fun <T> MutableList<T>.padTo(size: Int, element: T)

Grows this list in place to size elements by appending element.

Link copied to clipboard
inline fun <T> Iterable<T>.partitionIndexed(predicate: (index: Int, T) -> Boolean): Pair<List<T>, List<T>>

Splits this iterable into a pair of lists using predicate, which also receives each element's index.

Link copied to clipboard
fun <T> List<T>.penultimate(): T

Returns the element before the last one.

Link copied to clipboard

Returns the element before the last one, or null if the list has fewer than two elements.

Link copied to clipboard
@JvmName(name = "percentileOfInt")
fun List<Int>.percentile(p: Double): Double
@JvmName(name = "percentileOfLong")
fun List<Long>.percentile(p: Double): Double

Returns the p-th percentile of this list using linear interpolation between closest ranks.

Link copied to clipboard
@JvmName(name = "percentileOrNullOfInt")
fun List<Int>.percentileOrNull(p: Double): Double?
@JvmName(name = "percentileOrNullOfLong")
fun List<Long>.percentileOrNull(p: Double): Double?

Returns the p-th percentile of this list, or null if the list is empty.

Link copied to clipboard
@JvmName(name = "productOfDouble")
fun Iterable<Double>.product(): Double
@JvmName(name = "productOfLong")
fun Iterable<Long>.product(): Long

Returns the product of all elements.

@JvmName(name = "productOfInt")
fun Iterable<Int>.product(): Long

Returns the product of all elements, accumulated as a Long.

Link copied to clipboard
inline fun <T> MutableList<T>.removeFirstWhere(predicate: (T) -> Boolean): Boolean

Removes the first element matching predicate and returns true, or returns false if none matches.

Link copied to clipboard
inline fun <T> MutableList<T>.removeLastWhere(predicate: (T) -> Boolean): Boolean

Removes the last element matching predicate and returns true, or returns false if none matches.

Link copied to clipboard
fun <T> List<T>.repeated(times: Int): List<T>

Returns a list containing this list's elements repeated times times in sequence.

Link copied to clipboard
fun <T> List<T>.replacedAt(index: Int, element: T): List<T>

Returns a copy of this list with the element at index replaced by element.

Link copied to clipboard
fun <T> MutableList<T>.rotate(distance: Int)

Rotates this list in place by distance positions.

Link copied to clipboard
fun <T> List<T>.rotated(distance: Int): List<T>

Returns a copy of this list rotated by distance positions.

Link copied to clipboard
fun <T> List<T>.second(): T

Returns the second element.

Link copied to clipboard
fun <T> List<T>.secondOrNull(): T?

Returns the second element, or null if the list has fewer than two elements.

Link copied to clipboard
fun <T> List<T>.splitAt(index: Int): Pair<List<T>, List<T>>

Splits the list into the elements before index and the elements from index onward.

Link copied to clipboard
inline fun <T> Iterable<T>.splitBy(isDelimiter: (T) -> Boolean): List<List<T>>

Splits this iterable into segments separated by elements matching isDelimiter, dropping the delimiters.

Link copied to clipboard
fun <T> List<T>.startsWith(prefix: List<T>): Boolean

Returns true if this list begins with the elements of prefix in order.

Link copied to clipboard
@JvmName(name = "stdDevOfInt")
fun List<Int>.stdDev(): Double
@JvmName(name = "stdDevOfLong")
fun List<Long>.stdDev(): Double

Returns the population standard deviation of this list.

Link copied to clipboard
@JvmName(name = "stdDevOrNullOfInt")
fun List<Int>.stdDevOrNull(): Double?
@JvmName(name = "stdDevOrNullOfLong")
fun List<Long>.stdDevOrNull(): Double?

Returns the population standard deviation of this list, or null if the list is empty.

Link copied to clipboard
fun <T> MutableList<T>.swap(i: Int, j: Int)

Exchanges the elements at i and j in place.

Link copied to clipboard
fun <T> List<T>.swapped(i: Int, j: Int): List<T>

Returns a copy of this list with the elements at i and j exchanged.

Link copied to clipboard
fun <C : Collection<*>> C.takeIfNotEmpty(): C?

Returns this collection if it is not empty, or null otherwise.

fun <M : Map<*, *>> M.takeIfNotEmpty(): M?

Returns this map if it is not empty, or null otherwise.

Link copied to clipboard
fun <T> List<T>.third(): T

Returns the third element.

Link copied to clipboard
fun <T> List<T>.thirdOrNull(): T?

Returns the third element, or null if the list has fewer than three elements.

Link copied to clipboard
fun <T> MutableSet<T>.toggle(element: T): Boolean

Adds element if absent or removes it if present, and returns whether the set contains it afterwards.

Link copied to clipboard
fun <T> Set<T>.toggled(element: T): Set<T>

Returns a copy of this set with element added if absent or removed if present.

Link copied to clipboard
fun <T> List<List<T>>.transposed(): List<List<T>>

Returns this list of rows transposed into a list of columns.

Link copied to clipboard
inline fun <T> MutableList<T>.updateAt(index: Int, transform: (T) -> T)

Replaces the element at index with the result of applying transform to it.

Link copied to clipboard
@JvmName(name = "varianceOfInt")
fun List<Int>.variance(): Double
@JvmName(name = "varianceOfLong")
fun List<Long>.variance(): Double

Returns the population variance of this list.

Link copied to clipboard
@JvmName(name = "varianceOrNullOfInt")
fun List<Int>.varianceOrNull(): Double?
@JvmName(name = "varianceOrNullOfLong")
fun List<Long>.varianceOrNull(): Double?

Returns the population variance of this list, or null if the list is empty.

Link copied to clipboard

Returns each element paired with its successor, where the last element wraps around to the first.