library / org.akop.kotx.ext.collections / android.util.SparseArray

Extensions for android.util.SparseArray

filter

fun <V> SparseArray<V>.filter(predicate: (Int, V) -> Boolean): SparseArray<V>

Filters all entries matching given predicate into a new SparseArray.

filterTo

fun <V> SparseArray<V>.filterTo(destination: SparseArray<V>, predicate: (Int, V) -> Boolean): SparseArray<V>

Writes all entries matching given predicate to destination array.

forEach

fun <V> SparseArray<V>.forEach(action: (Int, V) -> Unit): Unit

Performs given action on each key/value pair.

getOrPut

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.

plusAssign

operator fun <T> SparseArray<T>.plusAssign(array: SparseArray<T?>): Unit

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

set

operator fun <T> SparseArray<T>.set(key: Int, value: T?): Unit

Sets value for specified key.

values

val <T> SparseArray<T>.values: List<T>

Returns a list containing all values in a SparseArray.