Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OleksiiBulba opened this issue Jul 19, 2023 · 1 comment
Labels

Comments

@OleksiiBulba
Copy link

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!

@derrabus
Copy link
Member

I don't see much value in adding that functionality to the library. Creating a new collection with a different index can be done in userland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants