GetOrAdd
is a convenient method for ConcurrentDictionary
but not for other IDictionary
types in the standard class library. This method is often used to cache results of pure functions, ie functions that always yield a deterministic result for each argument.
This package provides GetOrAdd
method to all IDictionary
types.
Example:
using CLSS;
var NumberSpellings = new Dictionary<int, string>();
Func<int, string> NumberToSpelling = n => { /* Implementation */ };
var spelling_285 = NumberSpellings.GetOrAdd(285, NumberToSpelling);