is there an existing solution for this function i ...
# announcements
d
is there an existing solution for this function i implemented?
Copy code
// Applies `process` to each iterable item until it returns non-null, returning the result of the application.
fun <A, B> Iterable<A>.findNotNull(process: (A) -> B?): B? {
    for (element in this) process(element).let { if (it != null) return it }
    return null
}

listOf(null, null, 42, null).findNotNull { x -> x }   // 42
listOf(null, null, null, null).findNotNull { x -> x } // null