mapNotNull

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

Applies transform once per element in iteration order and retains only non-null results.

Creates a new list without changing the source. Accepted results retain their order. Exceptions from iteration or the callback propagate to the caller. The inline callback supports non-local returns.

Receiver

elements to visit in their iteration order.

Return

a new read-only list of non-null results; empty if none are produced.

Parameters

transform

transformation returning a value to include, or null to omit it.

See also