Skip to content

Instantly share code, notes, and snippets.



Created Sep 21, 2017
What would you like to do?
Simple function to memoize function calls
fun <T, U> memoized(function: (T) -> U): (T) -> U {
val cache = mutableMapOf<T, U>()
return { t -> cache.getOrPut(t) { function(t) } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment