collections
collections copied to clipboard
Question: is there any way to reindex a collection using callable function that defines index?
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!