FuncExtensionsMemoizeT, TResult Method (FuncT, 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<T, TResult> Memoize<T, TResult>( this Func<T, TResult> func )
Func<int, int> inc = x => x + 1; var memoizedInc = inc.Memoize(); Console.WriteLine(memoizedInc(1)); // Calls inc and caches the result Console.WriteLine(memoizedInc(1)); // Reads the result from the cache