Skip to content

feat(support): with and without methods for manipulatesarray#2094

Open
iamdadmin wants to merge 2 commits intotempestphp:3.xfrom
iamdadmin:3.x-with-without-manipulatesarray
Open

feat(support): with and without methods for manipulatesarray#2094
iamdadmin wants to merge 2 commits intotempestphp:3.xfrom
iamdadmin:3.x-with-without-manipulatesarray

Conversation

@iamdadmin
Copy link
Copy Markdown
Contributor

Suggested from #2092 - introduces convenience methods ->with and ->without for ManipulatesArray, and tests.

Usage examples from the test:

    public function test_with(): void
    {
        $collection = arr([
            'first_name' => 'John',
            'last_name' => 'Doe',
            'age' => 42,
        ]);
        $current = $collection
            ->with(['first_name', 'last_name'])
            ->toArray();
        $expected = [
            'first_name' => 'John',
            'last_name' => 'Doe',
        ];

        $this->assertSame($expected, $current);
    }

    public function test_without(): void
    {
        $collection = arr([
            'first_name' => 'John',
            'last_name' => 'Doe',
            'age' => 42,
        ]);
        $current = $collection
            ->without(['age'])
            ->toArray();
        $expected = [
            'first_name' => 'John',
            'last_name' => 'Doe',
        ];

        $this->assertSame($expected, $current);
    }

Copy link
Copy Markdown
Member

@innocenzi innocenzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the methods, but not the names; I don't think generic method names are helpful and I'd like to see more specific ones.

These are essentially "filter" methods, so maybe with should be an update to the existing filter where it accepts an array, and without should be a new reject method?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants