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

[8.x] Add hasAny() Method to Collections #39155

Merged
merged 3 commits into from
Oct 11, 2021
Merged

[8.x] Add hasAny() Method to Collections #39155

merged 3 commits into from
Oct 11, 2021

Conversation

intrepidws
Copy link
Contributor

This PR adds support for a hasAny() method to collections. A similar method already exists as an array helper, in the MessageBag class and in the InteractsWithInput class. Since it already exists in all of those places, I think it makes sense to add it to the Collection classes for full parity.

This example would return true:

collect(['first' => 'Hello', 'second' => 'World'])->hasAny(['first', 'fourth']);

While this would return false:

collect(['first' => 'Hello', 'second' => 'World'])->hasAny(['third', 'fourth']);

@driesvints
Copy link
Member

Ping @JosephSilber

@JosephSilber
Copy link
Member

Looks good, though it needs a test verifying that it's actually lazy.

@GrahamCampbell GrahamCampbell changed the title Add hasAny() Method to Collections [8.x] Add hasAny() Method to Collections Oct 9, 2021
@intrepidws
Copy link
Contributor Author

I have added the requested test. I'll fully admit that lazy collections aren't a strength of mine, but I think that I did it right.

Copy link
Member

@JosephSilber JosephSilber left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Just suggesting an additional test case.

@intrepidws
Copy link
Contributor Author

I'm not sure why that test is failing - seems unrelated to this PR? I ran the tests locally on PHP8 and it worked fine.

@driesvints
Copy link
Member

@intrepidws restarted the build for ya.

@taylorotwell taylorotwell merged commit 758565c into laravel:8.x Oct 11, 2021
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
* WIP

* Test to verify hasAny() method is actually lazy

* Additional test to verify hasAny() method is actually lazy
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.

None yet

4 participants