I wonder if it’s quite obvious, but `lazy` is not ...
# random
o
I wonder if it’s quite obvious, but
lazy
is not only for properties, here is how you can do lazy computations:
Copy code
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
Copy code
x.value // compute!