public function sort(\Closure $p)
    {
        $elements = $this->toArray();

        if (!uasort($elements, $p)) {
            throw new \InvalidArgumentException('Sort failed.');
        }

        return new static(array_values($elements));
    }