does kotlin have a way to turn a function into one...
# announcements
r
does kotlin have a way to turn a function into one which is evaluated only once? Something like
Copy code
fun <R> (() -> R).evalOnce(): () -> R {
    val v by lazy { this() }
    return { v }
}
but which works also for functions with one or more parameters?
p
Do you mean memoization?
r
kind of yes
j
Well part of the memoization would involve making sure that the parameters matched a previous call. You'd probably have to roll your own on this one.
s
It seems you want a cache
👍 1
r
ok, thanks for the information
j
If you want to make this generic, I'd suggest that you make your memoization function, a simple way to get around the multi-argument problem is just make a version of the function that takes one arg and when you need more args, throw those into a data class.