FuncExtensionsMemoizeT1, T2, TResult Method (FuncT1, T2, TResult) |
Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use.
A limitless cache is used.
Namespace: Beerendonk.Memoization
public static Func<T1, T2, TResult> Memoize<T1, T2, TResult>( this Func<T1, T2, TResult> func )
Func<int, int, int> add = (x, y) => x + y; var memoizedAdd = add.Memoize(); Console.WriteLine(memoizedAdd(1, 2)); // Calls add and caches the result Console.WriteLine(memoizedAdd(1, 2)); // Reads the result from the cache