More Memoization
I had to cache the results a couple methods recently, and only after I had done it a few times, I realized I should just write a memoization extension for System.Func. public static Func<T, TResult> Memoize<T, TResult>(this Func<T, TResult> func) { Dictionary<T, TResult> dict = new Dictionary<T, TResult>(); return input => { if (!dict.ContainsKey(input)) […]
More