orangy
lazy
is not only for properties, here is how you can do lazy computations:
val x = lazy {
val a = lazy {
Random().nextInt(10).apply { println("computed [a] as $this") }
}
val b = lazy {
42.apply { println("computed [b] as $this") }
}
println("computing result")
if (a.value < 5) {
a.value + 1
} else {
a.value + b.value
}.apply { println("result: $this") }
}
and then
x.value // compute!