Click or drag to resize
FuncExtensionsMemoizeT1, T2, T3, TResult Method (FuncT1, T2, T3, TResult, ICacheTupleT1, 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.

Namespace: Beerendonk.Memoization
Assembly: Memoization (in Memoization.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static Func<T1, T2, T3, TResult> Memoize<T1, T2, T3, TResult>(
	this Func<T1, T2, T3, TResult> func,
	ICache<Tuple<T1, T2, T3>, TResult> cache
)

Parameters

func
Type: SystemFuncT1, T2, T3, TResult
The function to memoize.
cache
Type: Beerendonk.MemoizationICacheTupleT1, T2, T3, TResult
The cache to use.

Type Parameters

T1
The type of the first argument.
T2
The type of the second argument.
T3
The type of the third argument.
TResult
The type of the result.

Return Value

Type: FuncT1, T2, T3, 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 FuncT1, T2, T3, 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
ICache<Tuple<int, int, int>, int> cache = CacheFactory.LimitlessCache<Tuple<int, int, int>, int>();
Func<int, int, int, int> add = (x, y, z) => x + y + z;
var memoizedAdd = add.Memoize(cache);
Console.WriteLine(memoizedAdd(1, 2));  // Calls add and caches the result
Console.WriteLine(memoizedAdd(1, 2));  // Reads the result from the cache
See Also