Click or drag to resize
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
Assembly: Memoization (in Memoization.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static Func<T, TResult> Memoize<T, TResult>(
	this Func<T, TResult> func
)

Parameters

func
Type: SystemFuncT, TResult
The function to memoize.

Type Parameters

T
The type of the argument.
TResult
The type of the result.

Return Value

Type: FuncT, TResult
A memoized version of the function.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type FuncT, TResult. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
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
See Also