public static function memoize(callable $callback, $key = null) : \Closure
    {
        return function(...$args) use ($callback, $key) {

            // Determine which cache key to use.
            $key = null === $key
                ? static::hash($callback, $args)
                : (string) (is_callable($key) ? $key($callback, ...$args) : $key);

            // If we don't already have a hit for the cache key, populate it with the result of invocation.
            if (!array_key_exists($key, static::$memory)) {
                static::$memory[$key] = $callback(...$args);
            }

            return static::$memory[$key];
        };
    }