Package-level declarations

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val <T> List<T>.midIndex: Int

get mid index of a list

Link copied to clipboard

Returns a list containing all values in a SparseArray.

Functions

Link copied to clipboard
fun <T> MutableCollection<T>.addAll(vararg items: T)
Link copied to clipboard
fun <S : MutableCollection<T>, T> S.addAnd(item: T): S
fun <S : MutableList<T>, T> S.addAnd(index: Int, item: T): S
Link copied to clipboard
infix fun <E> ArrayList<E>.addIfNotExist(obj: E): Boolean

Adds E to this list if the same doesn't exist

infix fun <E> MutableList<E>.addIfNotExist(obj: E): Boolean

Adds E to this list if the same doesn't previously exist. so

fun <K, E> HashMap<K, E>.addIfNotExist(key: K, obj: E): E?
fun <K, E> MutableMap<K, E>.addIfNotExist(key: K, obj: E): E?

Adds E to this map if the same doesn't exist

Link copied to clipboard

Adds the item if it is not in the collection or removes it if it is.

Link copied to clipboard
fun <T> MutableList<T>.addOrReplace(item: T, predicate: (T) -> Boolean): Boolean

Replaces the first item within the list that matches the given predicate or adds the item to the list if none match.

Link copied to clipboard
inline fun <T> T.addToList(list: MutableList<T>): T
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
infix fun <T> T.appendTo(list: List<T>): List<T>
Link copied to clipboard

Returns an empty new ArrayDeque.

fun <T> arrayDequeOf(vararg elements: T): ArrayDeque<T>

Returns a new ArrayDeque with the given elements.

Link copied to clipboard
inline fun <V> Iterable<V>.associateBy(keySelector: (V) -> Int): SparseArray<V>

Populates and returns a SparseArray by populating with keys provided by keySelector and values that are the elements themselves.

inline fun <T, V> Iterable<T>.associateBy(keySelector: (T) -> Int, valueTransform: (T) -> V): SparseArray<V>

Populates and returns a SparseArray by populating with keys provided by keySelector and values provided by valueTransform.

Link copied to clipboard
inline fun <V, M : SparseArray<in V>> Iterable<V>.associateByTo(destination: M, keySelector: (V) -> Int): M

Populates and returns the destination array by populating with keys provided by keySelector and values that are the elements themselves.

inline fun <T, V, M : SparseArray<in V>> Iterable<T>.associateByTo(destination: M, keySelector: (T) -> Int, valueTransform: (T) -> V): M

Populates and returns the destination array by populating with keys provided by keySelector and values provided by valueTransform.

Link copied to clipboard
fun <T> combinations(vararg listOfList: List<T>): List<List<T>>
@JvmName(name = "combinations")
fun <A, B> combinations(listA: List<A>, listB: List<B>): List<Pair<A, B>>
@JvmName(name = "combinations")
fun <A, B, C> combinations(listA: List<A>, listB: List<B>, listC: List<C>): List<Triple<A, B, C>>
Link copied to clipboard
@JvmName(name = "combinationsExtension")
fun <A, B> List<A>.combinations(listB: List<B>): List<Pair<A, B>>
@JvmName(name = "combinationsExtension")
fun <A, B, C> List<A>.combinations(listB: List<B>, listC: List<C>): List<Triple<A, B, C>>
Link copied to clipboard
fun <T1, T2> Iterable<T1>.combine(other: Iterable<T2>): List<Pair<T1, T2>>
inline fun <T1, T2, R> Iterable<T1>.combine(other: Iterable<T2>, transform: (thisItem: T1, otherItem: T2) -> R): List<R>
Link copied to clipboard
inline fun <T1, T2, R> Iterable<T1>.combineToMutableList(other: Iterable<T2>, transform: (thisItem: T1, otherItem: T2) -> R): MutableList<R>
Link copied to clipboard
fun <T, S> MutableList<T>.compose(mixList: List<S>, mixFilter: (T, S) -> Boolean, mixOperate: (T?, S) -> T, removeCannotMix: Boolean = true)
Link copied to clipboard
fun <T> List<List<T>>.concat(): List<T>
Link copied to clipboard
Link copied to clipboard
inline fun <T> Iterable<T>.contains(predicate: (T) -> Boolean): Boolean

Returns true if an element matching the given predicate was found.

Link copied to clipboard

Checks if element is contained (ignoring case) by the array

Link copied to clipboard
fun count(start: Byte, step: Byte = 1): Sequence<Byte>
fun count(start: Double, step: Double = 1.0): Sequence<Double>
fun count(start: Float, step: Float = 1.0f): Sequence<Float>
fun count(start: Int, step: Int = 1): Sequence<Int>
fun count(start: Long, step: Long = 1): Sequence<Long>
fun count(start: Short, step: Short = 1): Sequence<Short>

Make an iterator that returns values starting with start with evenly space step.

inline fun <T> count(start: T, step: T, crossinline add: (T, T) -> T): Sequence<T>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <T> Iterable<T>.cycle(): Sequence<T>

Make an iterator returning elements from the iterable and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely.

Link copied to clipboard
Link copied to clipboard
fun <T> dequeOf(): Deque<T>

Returns an empty new Deque.

fun <T> dequeOf(vararg elements: T): Deque<T>

Returns a new Deque with the given elements.

Link copied to clipboard
fun <T> MutableList<T>.doIf(predicate: Boolean, action: MutableList<T>.() -> Any): MutableList<T>
Link copied to clipboard
fun <T> Collection<T>.doIfContained(t: T, func: T.() -> Unit): Boolean
Link copied to clipboard
fun <T> List<T>.encapsulate(): List<List<T>>
Link copied to clipboard
inline fun <V> SparseArray<V>.filter(predicate: (Int, V) -> Boolean): SparseArray<V>

Filters all entries matching given predicate into a new SparseArray.

Link copied to clipboard
fun <K, V> Map<K, V?>.filterNotNullValues(): Map<K, V>
Link copied to clipboard
inline fun <V> SparseArray<V>.filterTo(destination: SparseArray<V>, predicate: (Int, V) -> Boolean): SparseArray<V>

Writes all entries matching given predicate to destination array.

Link copied to clipboard
Link copied to clipboard
inline fun <T> Array<T>.firstIndexed(filter: (index: Int, T) -> Boolean, onNext: (index: Int, T) -> Unit = { _, _ -> }, onSuccess: () -> Unit = {}, onFail: () -> Unit = {}, onComplete: () -> Unit = {})
Link copied to clipboard
fun <T> List<T?>.firstNotNull(): T

Returns the first element which is not null.

Link copied to clipboard
inline fun <T> Iterable<T?>.firstNotNullOrElse(defaultValue: () -> T): T
inline fun <T> List<T?>.firstNotNullOrElse(defaultValue: () -> T): T

Returns the first element which is not null, or the result of calling the defaultValue function if there are no elements or all elements are null.

Link copied to clipboard
inline fun <T> Iterable<T>.firstOrElse(predicate: (T) -> Boolean, defaultValue: () -> T): T

Returns the first element matching the given predicate, or the result of calling the defaultValue function if no such element is found.

Link copied to clipboard
inline fun <T, R> Iterable<T>.flatMapToMutableList(transform: (T) -> Iterable<R>): MutableList<R>
Link copied to clipboard
fun <T> flatten(vararg elements: List<T>): List<T>
fun <T> flatten(list: List<List<T>>): List<T>
Link copied to clipboard
fun <K, V> Map<K, List<V>>.flatten(): List<Any?>
Link copied to clipboard
inline fun <V> SparseArray<V>.forEach(action: (Int, V) -> Unit)

Performs given action on each key/value pair.

Link copied to clipboard
inline fun <E> Iterable<E>.forEachApply(action: E.() -> Unit)
Link copied to clipboard
inline fun <E> Iterable<E>.forEachApplyIndexed(action: E.(index: Int) -> Unit)
Link copied to clipboard
inline fun <T> ArrayList<T>.forEachReversed(f: (T) -> Unit)

Iterate the receiver ArrayList backwards.

inline fun <T> List<T>.forEachReversed(f: (T) -> Unit)

Iterate the receiver List backwards.

Link copied to clipboard
inline fun <T> ArrayList<T>.forEachReversedIndexed(f: (Int, T) -> Unit)

Iterate the receiver ArrayList backwards.

inline fun <T> List<T>.forEachReversedIndexed(f: (Int, T) -> Unit)

Iterate the receiver List backwards.

Link copied to clipboard
Link copied to clipboard
inline fun <V> SparseArray<V>.getOrPut(key: Int, defaultValue: () -> V): V

Gets value with specific key. If the value is not present, calls defaultValue to obtain a non-null value which is placed into the array, then returned.

Link copied to clipboard
fun <T> List<T>.getRandom(generator: Random = Random()): T
Link copied to clipboard
fun <T> List<T>.getStringRepresentation(maxElements: Int = Integer.MAX_VALUE): String
Link copied to clipboard
fun <K, V> Map<K, List<V>>.indexInSection(element: V): Int
Link copied to clipboard
fun <E> List<E>.indexOf(item: E?): Int
Link copied to clipboard
fun <T : Comparable<T>> indexOfMin(arr: Array<T>): Int

Find the index of the minimal element of an array.

Link copied to clipboard
fun <T> Collection<T>.init(): List<T>
Link copied to clipboard
inline fun <T> initArrayOf(size: Int, predicate: (index: Int) -> T): Array<T>
Link copied to clipboard
Link copied to clipboard
fun <T> Set<T>?.isEmpty(): Boolean
Link copied to clipboard
Link copied to clipboard
fun <E> Collection<E>.isLast(position: Int): Boolean
fun <E> List<E>.isLast(element: E): Boolean
fun <T> List<T>?.isLast(index: Int): Boolean
Link copied to clipboard
inline fun <T, R> T.isListAndNotNullOrEmpty(actionFalse: () -> R, actionTrue: () -> R): R
Link copied to clipboard
inline fun <T, R> T.isListAndNullOrEmpty(actionFalse: () -> R, actionTrue: () -> R): R
Link copied to clipboard
Link copied to clipboard
fun <K, V> Map<K, V>.keyAt(value: V): K?
Link copied to clipboard
fun <K, V> Map<K, List<V>>.keyAtIndex(index: Int): K?
Link copied to clipboard
fun <K, V> Map<K, List<V>>.keyIndex(key: K?): Int
Link copied to clipboard
fun <T, E> List<Pair<T, E>>.keySet(): Set<T>
fun <T, E> Map<T, E>.keySet(): Set<T>

Isolate the keys out of a list of pairs and store them in a set

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

Returns the last element which is not null.

Link copied to clipboard
inline fun <T> Iterable<T?>.lastNotNullOrElse(defaultValue: () -> T): T
inline fun <T> List<T?>.lastNotNullOrElse(defaultValue: () -> T): T

Returns the last element which is not null, or the result of calling the defaultValue function if there are no elements or all elements are null.

Link copied to clipboard
inline fun <T> Iterable<T>.lastOrElse(predicate: (T) -> Boolean, defaultValue: () -> T): T
inline fun <T> List<T>.lastOrElse(predicate: (T) -> Boolean, defaultValue: () -> T): T

Returns the last element matching the given predicate, or the result of calling the defaultValue function if no such element is found.

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

Finds the first least common item

Link copied to clipboard
fun <T> listEqualsIgnoreOrder(list1: List<T>, list2: List<T>): Boolean
Link copied to clipboard
inline fun <T : Any> MutableMap<String, Any>.makeTo(fromKey: String, toKey: String, block: (from: Any?) -> T)
Link copied to clipboard
inline fun <T, R : Any> Iterable<T>.mapNotNullToSet(transform: (T) -> R?): Set<R>
Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToMutableList(transform: (T) -> R): MutableList<R>
Link copied to clipboard
inline fun <T, R> Iterable<T>.mapToSet(transform: (T) -> R): Set<R>
Link copied to clipboard
fun <T> T.mergeWith(vararg items: T): MutableList<T>

fun <T> T.mergeWith(items: Iterable<T>): MutableList<T>

LIST

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

Gets mid element

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

Finds the first most common item

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

Moves the given T item to the specified index

Link copied to clipboard
fun <T> MutableList<T>.moveAll(newIndex: Int, predicate: (T) -> Boolean)

Moves all items meeting a predicate to the given index

Link copied to clipboard
fun <T> MutableList<T>.moveAt(oldIndex: Int, newIndex: Int)

Moves the given item at the oldIndex to the newIndex

Link copied to clipboard
fun <T> MutableList<T>.moveDown(item: T): Boolean

Moves the given element T up the MutableList by an index increment unless it is at the bottom already which will result in no movement. Returns a Boolean indicating if move was successful

inline fun <T> MutableList<T>.moveDown(crossinline predicate: (T) -> Boolean): Boolean?

Moves first element T down an index that satisfies the given predicate, unless its already at the bottom

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

Moves all T elements down an index that satisfy the given predicate, unless they are already at the bottom

Link copied to clipboard
fun <T> MutableList<T>.moveDownAt(index: Int)

Moves the given element T up the MutableList by one increment unless it is at the bottom already which will result in no movement

Link copied to clipboard
fun <T> MutableList<T>.moveUp(item: T): Boolean

Moves the given element T up the MutableList by an index increment unless it is at the top already which will result in no movement. Returns a Boolean indicating if move was successful

inline fun <T> MutableList<T>.moveUp(crossinline predicate: (T) -> Boolean): Boolean?

Moves first element T up an index that satisfies the given predicate, unless its already at the top

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

Moves all T elements up an index that satisfy the given predicate, unless they are already at the top

Link copied to clipboard
fun <T> MutableList<T>.moveUpAt(index: Int)

Moves the given element at specified index up the MutableList by one increment unless it is at the top already which will result in no movement

Link copied to clipboard
inline fun <T> mutableListCreate(size: Int, create: (index: Int) -> T): MutableList<T>
Link copied to clipboard
fun <E> List<E>.nextAfter(element: E): E?
fun <E> List<E>.nextAfter(index: Int): E?
Link copied to clipboard
inline fun <T> Collection<T>.onDuplicatesRemoved(noDups: (collection: Set<T>) -> Unit = {})
Link copied to clipboard
inline fun <T> Collection<T>?.onNotNull(onNull: () -> Unit = {}, function: Collection<T>.() -> Unit)
Link copied to clipboard
inline fun <T> Collection<T>?.onNotNullOrEmpty(onNullOrEmpty: () -> Unit = {}, function: Collection<T>.() -> Unit)
Link copied to clipboard
inline fun <T> Collection<T>?.onNull(onNotNull: () -> Unit = {}, function: () -> Unit)
Link copied to clipboard
inline fun <T> Collection<T>?.onNullOrEmpty(onNotNullOrEmpty: () -> Unit = {}, function: () -> Unit)
Link copied to clipboard
fun <T> List<T>?.orEmptyString(string: String): String
Link copied to clipboard
infix operator fun ByteArray.plus(byte: Byte): ByteArray
infix operator fun ByteArray.plus(int: Int): ByteArray
Link copied to clipboard
operator fun <T> SparseArray<T>.plusAssign(array: SparseArray<T?>)

Copies keys and values from specified SparseArray, overwriting own key/value pairs.

Link copied to clipboard
inline fun <T, V> List<T>.pmap(operation: (T) -> V): List<V>

like map, but multithreaded. It uses the number of cores + 2 threads.

Link copied to clipboard
infix fun <T> T.prependTo(list: List<T>): List<T>
Link copied to clipboard
fun <E> List<E>.prevBefore(element: E): E?
fun <E> List<E>.prevBefore(index: Int): E?
Link copied to clipboard
inline fun <K, V> MutableMap<K, V>.putAllIfNotNull(vararg data: Pair<K, V?>, predicate: (V) -> Boolean = { true })
Link copied to clipboard
fun <K, V : CharSequence> MutableMap<K, V>.putAllIfNotNullOrBlank(vararg data: Pair<K, V?>)
Link copied to clipboard
fun <K, V : CharSequence> MutableMap<K, V>.putAllIfNotNullOrEmpty(vararg data: Pair<K, V?>)
Link copied to clipboard
fun <T> List<T>.random(): T
Link copied to clipboard
fun randomBooleanList(size: Int, generator: Random = Random()): List<Boolean>
Link copied to clipboard
fun randomDoubleList(size: Int, generator: Random = Random()): List<Double>
Link copied to clipboard
fun randomFloatList(size: Int, generator: Random = Random()): List<Float>
Link copied to clipboard
fun randomIntList(size: Int, generator: Random = Random()): List<Int>
fun randomIntList(size: Int, bound: Int, generator: Random = Random()): List<Int>
Link copied to clipboard
fun <T> List<T>.randomItem(): T
Link copied to clipboard
Link copied to clipboard
fun <E> MutableList<E>.removeElement(element: E): E?
Link copied to clipboard
fun <T> MutableList<T>.removeFirst(predicate: (T) -> Boolean): Boolean
Link copied to clipboard
inline fun <T> MutableList<T>.removeIfCompat(noinline filter: (T) -> Boolean)
Link copied to clipboard
fun <E> ArrayList<E>.removeInRange(position: Int, count: Int)
fun <E> MutableList<E>.removeInRange(position: Int, count: Int)
Link copied to clipboard
fun <T> T.repeat(): Sequence<T>

Make an iterator that returns element over and over again. Runs indefinitely.

fun <T> T.repeat(count: Int): Sequence<T>

Make an iterator that returns element over and over again. Runs count times.

Link copied to clipboard
fun <T, S> MutableMap<T, S>.replaceWith(map: Map<T, S>)
Link copied to clipboard
inline fun <T> Array<T>.resize(newSize: Int, creator: (Int) -> T): Array<T?>
Link copied to clipboard
fun <E> List<E>?.safeMutable(default: MutableList<E> = mutableListOf()): MutableList<E>

SAFE MUTABLE

fun <K, V> Map<K, V>?.safeMutable(default: MutableMap<K, V> = mutableMapOf()): MutableMap<K, V>
Link copied to clipboard
fun <T> LinkedList<T>.safePop(): T?
Link copied to clipboard
fun <T> ArrayList<T>.second(): T?
fun <T> List<T>.second(): T?
Link copied to clipboard
Link copied to clipboard
fun <K, V> Map<K, List<V>>.sectionKey(element: V): K?
Link copied to clipboard
operator fun <T> SparseArray<T>.set(key: Int, value: T?)

Sets value for specified key.

Link copied to clipboard
fun <T> MutableList<T>.shuffle(generator: Random = Random()): MutableList<T>
Link copied to clipboard
fun <T> List<T>.shuffled(): List<T>
Link copied to clipboard
fun <T> List<T>?.sizeOrZero(): Int
Link copied to clipboard
fun <T> Iterable<T>.skip(n: Int): List<T>

Returns the first element, or null if the list is empty.

Link copied to clipboard
fun <T> Comparator<T>.sort(list: MutableList<T>)
Link copied to clipboard
inline fun <E, R : Comparable<R>> MutableList<E>.sortedSelf(crossinline selector: (E) -> R?): MutableList<E>
Link copied to clipboard
fun <T> Collection<T>.split(): Pair<List<T>, List<T>>
fun <T> Collection<T>.split(index: Int): Pair<List<T>, List<T>>

fun <T> List<T>.split(partitionSize: Int): List<List<T>>

splits a list into sublists

Link copied to clipboard
fun <T> List<T>.startWith(item: T): List<T>
fun <T> List<T>.startWith(data: List<T>): List<T>
Link copied to clipboard
fun <T> List<T>.startWithIfNotEmpty(item: T): List<T>
Link copied to clipboard
inline fun <T> Iterable<T>.sumByFloat(selector: (T) -> Long): Float
Link copied to clipboard
inline fun <T> Iterable<T>.sumByLong(selector: (T) -> Long): Long
Link copied to clipboard

fun sumFromOne(n: Int): Int

This function uses a trick by a famous mathematician, Fredrick Gauss. Algorithm is O(1).

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

fun <T> MutableList<T>.swap(itemOne: T, itemTwo: T)

Swaps the index position of two items

fun <T> MutableList<T>.swap(index1: Int, index2: Int)

Swaps two values

Link copied to clipboard
fun <T> MutableList<T>.swapAsList(index1: Int, index2: Int): MutableList<T>
Link copied to clipboard
Link copied to clipboard
fun <T> List<T>.swapped(i: Int, j: Int): List<T>
Link copied to clipboard
operator fun List<Int>.times(by: Int): List<Int>

USAGE listOf(1, 2, 3) * 4 gives you 4, 8, 12

Link copied to clipboard
inline fun <T> Int.timesToListOf(predicate: (Int) -> T): List<T>
Link copied to clipboard
inline fun <T> Int.timesToMutableListOf(predicate: (Int) -> T): MutableList<T>
Link copied to clipboard
fun <T> Iterable<T>.toDeque(): Deque<T>

Returns a Deque filled with all elements of this collection.

Link copied to clipboard
fun <T> LongSparseArray<T>.toggle(key: Long, item: T)
Link copied to clipboard
inline fun <T, K> Iterable<T>.toHashMap(getKey: (T) -> K): HashMap<K, T>
inline fun <T, K, V> Iterable<T>.toHashMap(getKey: (T) -> K, getValue: (T) -> V): HashMap<K, V>
Link copied to clipboard
inline fun <T, K> Iterable<T?>.toHashMapNullable(getKey: (T?) -> K): HashMap<K, T?>
inline fun <T, K, V> Iterable<T?>.toHashMapNullable(getKey: (T?) -> K, getValue: (T?) -> V?): HashMap<K, V?>
Link copied to clipboard
fun ByteArray.toInt(isHighFront: Boolean = true): Int
Link copied to clipboard
Link copied to clipboard
inline fun <T> Iterable<T>.toLongSparseArray(getKey: (T) -> Long?): LongSparseArray<T>
Link copied to clipboard
Link copied to clipboard
inline fun <T> Iterable<T>.toSparseArray(getKey: (T) -> Int?): SparseArrayCompat<T>
Link copied to clipboard
inline fun MutableMap<String, Any>.transform(key: String, block: (Any?) -> String)
Link copied to clipboard
Link copied to clipboard
fun <T : Any> Iterable<T?>.trimNulls(): List<T>
Link copied to clipboard
Link copied to clipboard
inline fun <T> union(l: List<T>, vararg elements: T): List<T>
inline fun <T> union(l1: List<T>, l2: List<T>, vararg elements: T): List<T>
inline fun <T> union(l1: List<T>, l2: List<T>, l3: List<T>, vararg elements: T): List<T>
inline fun <T> union(l1: List<T>, l2: List<T>, l3: List<T>, l4: List<T>, vararg elements: T): List<T>
inline fun <T> union(l1: List<T>, l2: List<T>, l3: List<T>, l4: List<T>, l5: List<T>, vararg elements: T): List<T>
Link copied to clipboard
inline fun <T> List<T>.unmodifiable(): List<T>

Returns an unmodifiable version of a list.

inline fun <T> Set<T>.unmodifiable(): Set<T>

Returns an unmodifiable version of a set.

Link copied to clipboard
inline fun <T : TypedArray?, R> T.use(block: (T) -> R): R
Link copied to clipboard
fun <K, V> Map<K, V>.valueAt(key: V): V?
Link copied to clipboard
fun <T, E> List<Pair<T, E>>.valueSet(): Set<E>
fun <T, E> Map<T, E>.valueSet(): Set<E>

Isolate the values out of a list of pairs and store them in a set