{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ListUtilsKt

public final class ListUtilsKt


Summary

Public methods

static final boolean
<T extends Object> fastAll(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

Returns true if all elements match the given predicate.

static final boolean
<T extends Object> fastAny(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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

static final T
<T extends Object> fastFirstOrNull(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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

static final void
<T extends Object> fastForEach(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, Unit> action
)

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

static final void
<T extends Object> fastForEachIndexed(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull T, Unit> action
)

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

static final void
<T extends Object> fastForEachReversed(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, Unit> action
)

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

static final T
<T extends Object> fastLastOrNull(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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

static final @NonNull List<@NonNull R>
<T extends Object, R extends Object> fastMap(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull R> transform
)

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

static final @NonNull C
<T extends Object, R extends Object, C extends Collection<@NonNull R>> fastMapTo(
    @NonNull List<@NonNull T> receiver,
    @NonNull C destination,
    @NonNull Function1<@NonNull T, @NonNull R> transform
)

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

static final T
<T extends Object, R extends Comparable<@NonNull R>> fastMaxBy(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull R> selector
)

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

static final int
<T extends Object> fastSumBy(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Integer> selector
)

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

Public methods

fastAll

public static final boolean <T extends Object> fastAll(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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.

fastAny

public static final boolean <T extends Object> fastAny(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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.

fastFirstOrNull

public static final T <T extends Object> fastFirstOrNull(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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.

fastForEach

public static final void <T extends Object> fastForEach(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, Unit> action
)

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

public static final void <T extends Object> fastForEachIndexed(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function2<@NonNull Integer, @NonNull T, Unit> action
)

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

public static final void <T extends Object> fastForEachReversed(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, Unit> action
)

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.

fastLastOrNull

public static final T <T extends Object> fastLastOrNull(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Boolean> predicate
)

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.

fastMap

public static final @NonNull List<@NonNull R> <T extends Object, R extends Object> fastMap(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull R> transform
)

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

public static final @NonNull C <T extends Object, R extends Object, C extends Collection<@NonNull R>> fastMapTo(
    @NonNull List<@NonNull T> receiver,
    @NonNull C destination,
    @NonNull Function1<@NonNull T, @NonNull R> transform
)

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

public static final T <T extends Object, R extends Comparable<@NonNull R>> fastMaxBy(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull R> selector
)

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.

fastSumBy

public static final int <T extends Object> fastSumBy(
    @NonNull List<@NonNull T> receiver,
    @NonNull Function1<@NonNull T, @NonNull Integer> selector
)

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.