Bornyls Deen
05/27/2020, 8:16 PMfilterIsInstance
and first
but I imagine this is a little better performance wise as we are returning after the first match.
It's like first
is to filter
... `firstIsInstance`/`filterIsInstance` 😄
inline fun <reified T> Iterable<*>.firstIsInstance(): T? {
for (element in this) {
if (element is T) {
return element
}
}
return null
}
Dominaezzz
05/27/2020, 8:22 PMtodd.ginsberg
05/27/2020, 10:29 PMorNull
on the end to match the standard library. Maybe firstInstanceOfOrNull<T>()
?Bornyls Deen
05/28/2020, 8:24 AMchristophsturm
05/28/2020, 9:47 AM