FuncExtensionsMemoizeT1, T2, T3, TResult Method (FuncT1, T2, T3, 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, T3, TResult> Memoize<T1, T2, T3, TResult>( this Func<T1, T2, T3, TResult> func )
Func<int, int, int, int> add = (x, y, z) => x + y + z; var memoizedAdd = add.Memoize(); Console.WriteLine(memoizedAdd(1, 2, 3)); // Calls add and caches the result Console.WriteLine(memoizedAdd(1, 2, 3)); // Reads the result from the cache