min
10/02/2026, 6:50 AMList<T?> -> List<T>? method (or something similar) in the standard library? Almost like requireNoNulls, except I want a function that doesn’t throw.Vivek
10/02/2026, 7:48 AMfilterNotNull() will give you List<T>
if you really want List<T>? then you can do something like:
fun <T> List<T?>.toNonNullListOrNull(): List<T>? =
mapNotNull { it ?: return null }ephemient
10/02/2026, 6:03 PMmap, no need for mapNotNullfishy
10/03/2026, 8:26 AMfun <T> List<T?>.toNonNullListOrNull(): List<T>? = @Suppress("UNCHECKED_CAST") (takeIf { null !in it } as? List<T>?)
which isn't as clean because of the unchecked cast but it doesn't require allocating an entirely new listephemient
10/03/2026, 11:17 AM