4 ms·
They can! Kotlin provides the crossinline modifier on closures, which are allowed to return in their parent scope. While making Iterable<T>.map take a crossinli
by ohgodplsno 4y ago
They can! Kotlin provides the crossinline modifier on closures, which are allowed to return in their parent scope. While making Iterable<T>.map take a crossinline function is not the wisest idea, it has values in cases like Option<T>, allowing you to write something along the lines of
optionList.map { option ->
val result = option.getOrElse {
Log.d("Well that's fucked up")
return@map null
}
...more logic
}
and further in, result will not only have early returned, but will also have the proper, unwrapped type.