As discussed, would be good to rename this function to `memoize`.