public function groupBy(callable $callback, bool $preserveKeys = false): ArrayCollection
    {
        $items = [];

        foreach ($this->items as $key => $value) {
            $group = $callback($value, $key);

            if (!array_key_exists($group, $items)) {
                $items[$group] = new static();
            }

            $items[$group]->set($preserveKeys ? $key : null, $value);
        }

        return new static($items);
    }