later

inline fun <A> later(crossinline f: () -> A): Eval.Later<A>(source)

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.eval.*

fun main() {
//sampleStart
val lazyEvaled = Eval.later { "expensive computation" }
println(lazyEvaled.value())
//sampleEnd
}

"expensive computation" is only computed once since the results are memoized and multiple calls to value() will just return the cached value.