collections icon indicating copy to clipboard operation
collections copied to clipboard

Question: is there any way to reindex a collection using callable function that defines index?

Open OleksiiBulba opened this issue 1 year ago • 1 comments

Hello! I'm looking for a way to reindex a collection using my own callable function. It might be something like that:

interface ReadableCollection extends Countable, IteratorAggregate
{
    /* ... other methods */

    public function reindex(?Closure $p = null): ReadableCollection;

    /* ... other methods */
}

class ArrayCollection implements Collection, Selectable, Stringable
{
    /* ... other methods */

    public function reindex(?Closure $p = null): ReadableCollection
    {
        return $this->createFrom(array_combine(array_map($p, $array), $array));
    }

    /* ... other methods */
}

Is it possible somehow or might be implemented? Thanks for any help!

OleksiiBulba avatar Jul 19 '23 12:07 OleksiiBulba