1 package net.pterodactylus.sone.utils
3 class Memoize<in T, out R>(private val calc: (T) -> R) : (T) -> R {
5 private val values = mutableMapOf<T, R>()
7 override fun invoke(value: T) =
8 values.getOrPut(value, { calc(value) })
12 fun <T, R> ((T) -> R).memoize(): (T) -> R = Memoize(this)