Skip to content

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

@OleksiiBulba

Description

@OleksiiBulba

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions