karelpeeters
02/26/2018, 2:28 PMdata class Test(val num: Int) {
fun other(): Int {
println("hit")
return num + 5
}
}
Is there an elegant way to achieve something like list.first { it.other() > 5 }.other()
, but without having to call other
twice? list.map { it.other() }.first { it > 5 }
is also not really what I want, I basically want the minimum possible of other
calls.dany
02/26/2018, 2:35 PMfold
marstran
02/26/2018, 2:35 PMlist.asSequence().map { it.other() }.first { it > 5 }
karelpeeters
02/26/2018, 2:37 PMkarelpeeters
02/27/2018, 5:07 PMfirstNotNullResult
while typing something unrelated, turns out I'm not the only one that wants this: https://github.com/cbeust/klaxon/blob/master/src/main/kotlin/com/beust/klaxon/internal/Extensions.kt