Create a function that memoizes its results in a WeakHashMap.
Create a function that memoizes its results in a WeakHashMap.
Note that memoization is tricky if the objects that are memoized are mutable and the function being memoized returns a value that somehow depends on this mutable property.
For example, if we memoize a function that filters trees based on their position, and later modify the position of a tree, the memoized function will return the wrong value.
So in order to make it safe, the mkKey function can be used to provide a better key by including the mutable value.
A function that creates the key.
The function we want to memoize.