Skip to content

Instantly share code, notes, and snippets.

@acoffman
Last active May 17, 2016 21:13
Show Gist options
  • Save acoffman/1201988 to your computer and use it in GitHub Desktop.
Save acoffman/1201988 to your computer and use it in GitHub Desktop.
memoization
public static class Memoization {
public static Func<T,K> MemoizeFunction<T, K>(this Func<T, K> function) {
var table = new Dictionary<T, K>();
return (args) => {
if (table.ContainsKey(args)) return table[args];
var result = function(args);
table[args] = result;
return result;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment