Kotlin short circuit map{}.firstOrNull{}
Kotlin has lazily evaluated sequences that correspond to Java 8 streams, instead of invoking stream()
on a collection, you invoke asSequence()
:
return this
.asSequence()
.mapNotNull { transform(it) }
.firstOrNull()