Skip to content

Instantly share code, notes, and snippets.

@dimitarg
Created July 17, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimitarg/2309bfe044e85d4274f58030d8096026 to your computer and use it in GitHub Desktop.
Save dimitarg/2309bfe044e85d4274f58030d8096026 to your computer and use it in GitHub Desktop.
package demo
import fj.P
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class FjLazy<in R,T>(init: () -> T) : ReadOnlyProperty<R, T> {
val initIt = P.hardMemo(init)
override fun getValue(thisRef: R, property: KProperty<*>): T {
return initIt._1()
}
}
fun main(args: Array<String>) {
val foo: String by FjLazy {
println("initializing")
"asdasd"
}
println(foo)
println(foo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment