takeIfNotEmpty

fun <T> List<T>.takeIfNotEmpty(): List<T>?

Returns this list if it's not empty, or null if it is empty. This is a shorthand for ifEmpty { null }.

Return

The original list if it has at least one element, otherwise null.