mapIfNotEmpty

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

Returns a list containing the results of applying the given transform function to each element in the original list if the list is not null or empty. If the list is null or empty, it returns an empty list.

Return

A new list with the transformed elements, or an empty list if the original was null or empty.

Parameters

transform

The function to apply to each element.

Type Parameters

T

The type of elements in the original list.

R

The type of elements in the resulting list.