Skip to content

Arr::unique() cannot process non-scalar items #3

Description

@alexstandiford

It would be nice to have a way to filter out unique items that are non-scalar.

interface Something{
publicfunctiongetValue(): array; // or int, or string, whatever.
}
Arr::reduce([newSomething(1), Something(2), Something(1)], function($acc, $item)
{
$id = Str::createHash($item);
if (!isset($acc[$id])) {
$acc[$id] = $item;
}
returnarray_values($acc);
}

This is how you have to do it now, but ideally Arr::unique() would be smart enough to handle this. But right now Arr::unique() throws an exception if you try to use it on an array of objects.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions