memoize

fun <A, R> memoize(fn: (A) -> R): (A) -> R

Returns a function that caches every result of fn by argument.

The cache is unbounded and lives as long as the returned function. Each distinct argument invokes fn once; later calls return the cached result, including a cached null. Arguments are compared by Any.equals and Any.hashCode. The returned function is not thread-safe.

Type Parameters

A

the argument type.

R

the result type.


fun <A, B, R> memoize(fn: (A, B) -> R): (A, B) -> R

Returns a function that caches every result of fn by argument pair.

The cache is unbounded and lives as long as the returned function. Each distinct pair of arguments invokes fn once; later calls return the cached result, including a cached null. Arguments are compared by Any.equals and Any.hashCode. The returned function is not thread-safe.

Type Parameters

A

the first argument type.

B

the second argument type.

R

the result type.