later
Creates an Eval instance from a function deferring it's evaluation until .value()
is invoked memoizing the computed value.
Parameters
f
is a function or computation that will be called only once when .value()
is invoked for the first time.
import arrow.core.*
fun main() {
//sampleStart
val lazyEvaled = Eval.later { "expensive computation" }
println(lazyEvaled.value())
//sampleEnd
}
Content copied to clipboard
"expensive computation" is only computed once since the results are memoized and multiple calls to value()
will just return the cached value.