Memoize a simple referentially transparent function
Memoize a commutative function (the order of arguments doesn't matter).
Memoize a recursive function.
Memoize a recursive function. Recursive invocations will also go through the cache, therefore the function must accept it's cached variant as argument.
Memoization of recursive functions is equivalent to dynamic programming.
WARNING: Not stack safe.
Memoizing different types of functions.
Calling a memoized function with a set of arguments for the first time will save the result in a cache - a mutable.Map, possibly user-provided. Calling it with the same set of arguments subsequently will not perform the computation, but retrieve the cached value instead.
This is useful for computations that are expensive and are performed many times with the same arguments.
However, functions need to be referentially transparent (i.e. have no side effects) to preserve correctness.