androidx.compose.ui.util

Top-level functions summary

Double

Returns the Double value corresponding to a given bit representation.

Cmn
android
Float

Fast, approximate cube root function.

Cmn
inline Float
fastMaxOf(a: Float, b: Float, c: Float, d: Float)

Returns the largest of the given values.

Cmn
inline Float
fastMinOf(a: Float, b: Float, c: Float, d: Float)

Returns the smaller of the given values.

Cmn
Float

Returns the Float value corresponding to a given bit representation.

Cmn
android
Float
lerp(start: Float, stop: Float, fraction: Float)

Linearly interpolate between start and stop with fraction fraction between them.

Cmn
Int
lerp(start: Int, stop: Int, fraction: Float)

Linearly interpolate between start and stop with fraction fraction between them.

Cmn
Long
lerp(start: Long, stop: Long, fraction: Float)

Linearly interpolate between start and stop with fraction fraction between them.

Cmn
inline Long
packFloats(val1: Float, val2: Float)

Packs two Float values into one Long value for use in inline classes.

Cmn
inline Long
packInts(val1: Int, val2: Int)

Packs two Int values into one Long value for use in inline classes.

Cmn
inline T
<T : Any?> trace(sectionName: String, block: () -> T)
Cmn
android
inline Float

Unpacks the first absolute Float value in packFloats from its returned Long.

Cmn
inline Float

Unpacks the second absolute Float value in packFloats from its returned Long.

Cmn
inline Float

Unpacks the first Float value in packFloats from its returned Long.

Cmn
inline Float

Unpacks the second Float value in packFloats from its returned Long.

Cmn
inline Int
unpackInt1(value: Long)

Unpacks the first Int value in packInts from its returned ULong.

Cmn
inline Int
unpackInt2(value: Long)

Unpacks the second Int value in packInts from its returned ULong.

Cmn

Extension functions summary

inline Boolean
<T : Any?> List<T>.fastAll(predicate: (T) -> Boolean)

Returns true if all elements match the given predicate.

Cmn
inline Boolean
<T : Any?> List<T>.fastAny(predicate: (T) -> Boolean)

Returns true if at least one element matches the given predicate.

Cmn
inline Double

Ensures that this value is not less than the specified minimumValue.

Cmn
inline Float
Float.fastCoerceAtLeast(minimumValue: Float)

Ensures that this value is not less than the specified minimumValue.

Cmn
inline Double

Ensures that this value is not greater than the specified maximumValue.

Cmn
inline Float
Float.fastCoerceAtMost(maximumValue: Float)

Ensures that this value is not greater than the specified maximumValue.

Cmn
inline Double
Double.fastCoerceIn(minimumValue: Double, maximumValue: Double)

Returns this double value clamped in the inclusive range defined by minimumValue and maximumValue.

Cmn
inline Float
Float.fastCoerceIn(minimumValue: Float, maximumValue: Float)

Returns this float value clamped in the inclusive range defined by minimumValue and maximumValue.

Cmn
inline List<T>
<T : Any?, K : Any?> List<T>.fastDistinctBy(selector: (T) -> K)

Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.

Cmn
inline List<T>
<T : Any?> List<T>.fastFilter(predicate: (T) -> Boolean)

Returns a list containing only elements matching the given predicate.

Cmn
List<T>
<T : Any> List<T?>.fastFilterNotNull()

Returns a list containing all elements that are not null

Cmn
inline T
<T : Any?> List<T>.fastFirst(predicate: (T) -> Boolean)

Returns the first value that predicate returns true for

Cmn
inline T?
<T : Any?> List<T>.fastFirstOrNull(predicate: (T) -> Boolean)

Returns the first value that predicate returns true for or null if nothing matches.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastFlatMap(transform: (T) -> Iterable<R>)

Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

Cmn
inline R
<T : Any?, R : Any?> List<T>.fastFold(initial: R, operation: (acc, T) -> R)

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Cmn
inline Unit
<T : Any?> List<T>.fastForEach(action: (T) -> Unit)

Iterates through a List using the index and calls action for each item.

Cmn
inline Unit
<T : Any?> List<T>.fastForEachIndexed(action: (Int, T) -> Unit)

Iterates through a List using the index and calls action for each item.

Cmn
inline Unit
<T : Any?> List<T>.fastForEachReversed(action: (T) -> Unit)

Iterates through a List in reverse order using the index and calls action for each item.

Cmn
String
<T : Any?> List<T>.fastJoinToString(
    separator: CharSequence,
    prefix: CharSequence,
    postfix: CharSequence,
    limit: Int,
    truncated: CharSequence,
    transform: ((T) -> CharSequence)?
)

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

Cmn
inline T?
<T : Any?> List<T>.fastLastOrNull(predicate: (T) -> Boolean)

Returns the last element matching the given predicate, or null if no such element was found.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastMap(transform: (T) -> R)

Returns a list containing the results of applying the given transform function to each element in the original collection.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastMapIndexed(transform: (index: Int, T) -> R)

Returns a list containing the results of applying the given transform function to each element in the original collection.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastMapIndexedNotNull(transform: (index: Int, T) -> R?)

Returns a list containing the results of applying the given transform function to each element in the original collection.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastMapNotNull(transform: (T) -> R?)

Returns a list containing the results of applying the given transform function to each element in the original collection.

Cmn
inline C
<T : Any?, R : Any?, C : MutableCollection<R>> List<T>.fastMapTo(
    destination: C,
    transform: (T) -> R
)

Applies the given transform function to each element of the original collection and appends the results to the given destination.

Cmn
inline T?
<T : Any?, R : Comparable<R>> List<T>.fastMaxBy(selector: (T) -> R)

Returns the first element yielding the largest value of the given function or null if there are no elements.

Cmn
inline R?
<T : Any?, R : Comparable<R>> List<T>.fastMaxOfOrNull(selector: (T) -> R)

Returns the largest value among all values produced by selector function applied to each element in the collection or null if there are no elements.

Cmn
inline T?
<T : Any?, R : Comparable<R>> List<T>.fastMinByOrNull(selector: (T) -> R)

Returns the first element yielding the largest value of the given function or null if there are no elements.

Cmn
inline S
<S : Any?, T : S> List<T>.fastReduce(operation: (acc, T) -> S)

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.

Cmn
Int

Returns the closest integer to the argument, tying rounding to positive infinity.

Cmn
android
Int

Returns the closest integer to the argument, tying rounding to positive infinity.

Cmn
android
inline Int
<T : Any?> List<T>.fastSumBy(selector: (T) -> Int)

Returns the sum of all values produced by selector function applied to each element in the list.

Cmn
inline List<V>
<T : Any?, R : Any?, V : Any?> List<T>.fastZip(other: List<R>, transform: (a, b) -> 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.

Cmn
inline List<R>
<T : Any?, R : Any?> List<T>.fastZipWithNext(transform: (T, T) -> R)

Returns a list containing the results of applying the given transform function to each pair of two adjacent elements in this collection.

Cmn

Top-level functions

doubleFromBits

fun doubleFromBits(bits: Long): Double

Returns the Double value corresponding to a given bit representation.

fastCbrt

fun fastCbrt(x: Float): Float

Fast, approximate cube root function. Returns the cube root of x; for any x fastCbrt(-x) == -fastCbrt(x).

When x is:

The maximum error compared to kotlin.math.cbrt is:

  • 5.9604645E-7 in the range -1f..1f

  • 4.7683716E-6 in the range -256f..256f

  • 3.8146973E-5 in the range -65_536f..65_536f

  • 1.5258789E-4 in the range -16_777_216..16_777_216f

fastMaxOf

inline fun fastMaxOf(a: Float, b: Float, c: Float, d: Float): Float

Returns the largest of the given values. If any value is NaN, returns NaN. Preferred over kotlin.comparisons.maxOf() for 4 arguments as it avoids allocaing an array because of the varargs.

fastMinOf

inline fun fastMinOf(a: Float, b: Float, c: Float, d: Float): Float

Returns the smaller of the given values. If any value is NaN, returns NaN. Preferred over kotlin.comparisons.minfOf() for 4 arguments as it avoids allocaing an array because of the varargs.

floatFromBits

fun floatFromBits(bits: Int): Float

Returns the Float value corresponding to a given bit representation.

lerp

fun lerp(start: Float, stop: Float, fraction: Float): Float

Linearly interpolate between start and stop with fraction fraction between them.

lerp

fun lerp(start: Int, stop: Int, fraction: Float): Int

Linearly interpolate between start and stop with fraction fraction between them.

lerp

fun lerp(start: Long, stop: Long, fraction: Float): Long

Linearly interpolate between start and stop with fraction fraction between them.

packFloats

inline fun packFloats(val1: Float, val2: Float): Long

Packs two Float values into one Long value for use in inline classes.

packInts

inline fun packInts(val1: Int, val2: Int): Long

Packs two Int values into one Long value for use in inline classes.

trace

inline fun <T : Any?> trace(sectionName: String, block: () -> T): T

unpackAbsFloat1

inline fun unpackAbsFloat1(value: Long): Float

Unpacks the first absolute Float value in packFloats from its returned Long.

unpackAbsFloat2

inline fun unpackAbsFloat2(value: Long): Float

Unpacks the second absolute Float value in packFloats from its returned Long.

unpackFloat1

inline fun unpackFloat1(value: Long): Float

Unpacks the first Float value in packFloats from its returned Long.

unpackFloat2

inline fun unpackFloat2(value: Long): Float

Unpacks the second Float value in packFloats from its returned Long.

unpackInt1

inline fun unpackInt1(value: Long): Int

Unpacks the first Int value in packInts from its returned ULong.

unpackInt2

inline fun unpackInt2(value: Long): Int

Unpacks the second Int value in packInts from its returned ULong.

Extension functions

inline fun <T : Any?> List<T>.fastAll(predicate: (T) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

inline fun <T : Any?> List<T>.fastAny(predicate: (T) -> Boolean): Boolean

Returns true if at least one element matches the given predicate.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastCoerceAtLeast

inline fun Double.fastCoerceAtLeast(minimumValue: Double): Double

Ensures that this value is not less than the specified minimumValue.

fastCoerceAtLeast

inline fun Float.fastCoerceAtLeast(minimumValue: Float): Float

Ensures that this value is not less than the specified minimumValue.

fastCoerceAtMost

inline fun Double.fastCoerceAtMost(maximumValue: Double): Double

Ensures that this value is not greater than the specified maximumValue.

fastCoerceAtMost

inline fun Float.fastCoerceAtMost(maximumValue: Float): Float

Ensures that this value is not greater than the specified maximumValue.

fastCoerceIn

inline fun Double.fastCoerceIn(minimumValue: Double, maximumValue: Double): Double

Returns this double value clamped in the inclusive range defined by minimumValue and maximumValue. Unlike Float.coerceIn, the range is not validated: the caller must ensure that minimumValue is less than maximumValue.

fastCoerceIn

inline fun Float.fastCoerceIn(minimumValue: Float, maximumValue: Float): Float

Returns this float value clamped in the inclusive range defined by minimumValue and maximumValue. Unlike Float.coerceIn, the range is not validated: the caller must ensure that minimumValue is less than maximumValue.

fastDistinctBy

inline fun <T : Any?, K : Any?> List<T>.fastDistinctBy(selector: (T) -> K): List<T>

Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.

The elements in the resulting list are in the same order as they were in the source collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastFilter

inline fun <T : Any?> List<T>.fastFilter(predicate: (T) -> Boolean): List<T>

Returns a list containing only elements matching the given predicate.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastFilterNotNull

fun <T : Any> List<T?>.fastFilterNotNull(): List<T>

Returns a list containing all elements that are not null

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastFirst

inline fun <T : Any?> List<T>.fastFirst(predicate: (T) -> Boolean): T

Returns the first value that predicate returns true for

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

Throws
kotlin.NoSuchElementException

if no such element is found

fastFirstOrNull

inline fun <T : Any?> List<T>.fastFirstOrNull(predicate: (T) -> Boolean): T?

Returns the first value that predicate returns true for or null if nothing matches.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastFlatMap

inline fun <T : Any?, R : Any?> List<T>.fastFlatMap(transform: (T) -> Iterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastFold

inline fun <T : Any?, R : Any?> List<T>.fastFold(initial: R, operation: (acc, T) -> R): R

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Returns the specified initial value if the collection is empty.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastForEach

inline fun <T : Any?> List<T>.fastForEach(action: (T) -> Unit): Unit

Iterates through a List using the index and calls action for each item. This does not allocate an iterator like Iterable.forEach.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastForEachIndexed

inline fun <T : Any?> List<T>.fastForEachIndexed(action: (Int, T) -> Unit): Unit

Iterates through a List using the index and calls action for each item. This does not allocate an iterator like Iterable.forEachIndexed.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastForEachReversed

inline fun <T : Any?> List<T>.fastForEachReversed(action: (T) -> Unit): Unit

Iterates through a List in reverse order using the index and calls action for each item. This does not allocate an iterator like Iterable.forEach.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastJoinToString

fun <T : Any?> List<T>.fastJoinToString(
    separator: CharSequence = ", ",
    prefix: CharSequence = "",
    postfix: CharSequence = "",
    limit: Int = -1,
    truncated: CharSequence = "...",
    transform: ((T) -> CharSequence)? = null
): String

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

If the collection could be huge, you can specify a non-negative value of limit, in which case only the first limit elements will be appended, followed by the truncated string (which defaults to "...").

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastLastOrNull

inline fun <T : Any?> List<T>.fastLastOrNull(predicate: (T) -> Boolean): T?

Returns the last element matching the given predicate, or null if no such element was found.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

inline fun <T : Any?, R : Any?> List<T>.fastMap(transform: (T) -> R): List<R>

Returns a list containing the results of applying the given transform function to each element in the original collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMapIndexed

inline fun <T : Any?, R : Any?> List<T>.fastMapIndexed(transform: (index: Int, T) -> R): List<R>

Returns a list containing the results of applying the given transform function to each element in the original collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMapIndexedNotNull

inline fun <T : Any?, R : Any?> List<T>.fastMapIndexedNotNull(transform: (index: Int, T) -> R?): List<R>

Returns a list containing the results of applying the given transform function to each element in the original collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMapNotNull

inline fun <T : Any?, R : Any?> List<T>.fastMapNotNull(transform: (T) -> R?): List<R>

Returns a list containing the results of applying the given transform function to each element in the original collection.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMapTo

inline fun <T : Any?, R : Any?, C : MutableCollection<R>> List<T>.fastMapTo(
    destination: C,
    transform: (T) -> R
): C

Applies the given transform function to each element of the original collection and appends the results to the given destination.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMaxBy

inline fun <T : Any?, R : Comparable<R>> List<T>.fastMaxBy(selector: (T) -> R): T?

Returns the first element yielding the largest value of the given function or null if there are no elements.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMaxOfOrNull

inline fun <T : Any?, R : Comparable<R>> List<T>.fastMaxOfOrNull(selector: (T) -> R): R?

Returns the largest value among all values produced by selector function applied to each element in the collection or null if there are no elements.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastMinByOrNull

inline fun <T : Any?, R : Comparable<R>> List<T>.fastMinByOrNull(selector: (T) -> R): T?

Returns the first element yielding the largest value of the given function or null if there are no elements.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastReduce

inline fun <S : Any?, T : S> List<T>.fastReduce(operation: (acc, T) -> S): S

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.

Throws an exception if this collection is empty. If the collection can be empty in an expected way, please use reduceOrNull instead. It returns null when its receiver is empty.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

Parameters
operation: (acc, T) -> S

function that takes current accumulator value and an element, and calculates the next accumulator value.

Throws
kotlin.UnsupportedOperationException

if this collection is empty

fastRoundToInt

fun Float.fastRoundToInt(): Int

Returns the closest integer to the argument, tying rounding to positive infinity. Some values are treated differently:

  • NaN becomes 0

  • -Infinity or any value less than Integer.MIN_VALUE becomes Integer.MIN_VALUE.toFloat()

  • +Infinity or any value greater than Integer.MAX_VALUE becomes Integer.MAX_VALUE.toFloat()

fastRoundToInt

fun Double.fastRoundToInt(): Int

Returns the closest integer to the argument, tying rounding to positive infinity. Some values are treated differently:

  • NaN becomes 0

  • -Infinity or any value less than Integer.MIN_VALUE becomes Integer.MIN_VALUE.toFloat()

  • +Infinity or any value greater than Integer.MAX_VALUE becomes Integer.MAX_VALUE.toFloat()

fastSumBy

inline fun <T : Any?> List<T>.fastSumBy(selector: (T) -> Int): Int

Returns the sum of all values produced by selector function applied to each element in the list.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

inline fun <T : Any?, R : Any?, V : Any?> List<T>.fastZip(other: List<R>, transform: (a, b) -> V): 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.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.

fastZipWithNext

inline fun <T : Any?, R : Any?> List<T>.fastZipWithNext(transform: (T, T) -> R): List<R>

Returns a list containing the results of applying the given transform function to each pair of two adjacent elements in this collection.

The returned list is empty if this collection contains less than two elements.

Do not use for collections that come from public APIs, since they may not support random access in an efficient way, and this method may actually be a lot slower. Only use for collections that are created by code we control and are known to support random access.