Generic memoization wrapper for swift functions
I’m sure 30 seconds of googling could have shown me how to use Generics to make a function that memoized other functions but I thought I’d see what I could come up with on my own. It was actually pretty straight forward and makes me wonder what other generic functions/extensions could be made to enhance codebases in similar ways.
Note: In actual use a Hashtable like this is likely not what you want as it will contunue to grow and consume resources as you cause it to store new values. For diverse inputs or large inputs/results you will likely want something like a NSCache or a LRU cache.