danneu
01/03/2017, 1:11 AM// 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