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

Q: Strict collections intersection #45

Open
jaroslavlibal opened this issue Sep 8, 2017 · 4 comments
Open

Q: Strict collections intersection #45

jaroslavlibal opened this issue Sep 8, 2017 · 4 comments
Labels

Comments

@jaroslavlibal
Copy link

Hello,

is there any way how to compare collections strictly in the intersect() method?

The problem is that the in_array function used at https://github.com/DusanKasan/Knapsack/blob/master/src/collection_functions.php#L1301 causes the "Nesting level too deep - recursive dependency?" error when using a Collection of big objects.

I have been thinking about sending a PR with the third param set to true; however then I realised that it could be a big BC break for some users so I would like to ask you if you have some workaround suggestion instead, pelase.

Thanks!

@DusanKasan
Copy link
Owner

Hmm, i see. I think the solution could be to rewrite intersect so that we iterate over first 2 collections, create a temporary collection of the intersection, then repeat this over the next collection, the next and so on. This would not create a BC so it should be fine and will also lessen the memory load.

Would this solve your problem?

@jaroslavlibal
Copy link
Author

Hello, thanks for the answer. It would probably not help as the "problem" occurs also during the intersection of two collections which contains some PhpUnit mocks of Doctrine entities.

@DusanKasan
Copy link
Owner

DusanKasan commented Sep 11, 2017

Sorry, i misunderstood, i thought the problem was being with large collections. In the case of large objects we could introduce a method intersectStrict(collections...) or intersectUsing(comparator, collections...).

For now however, your best bet is calling filter/reject to remove the elements that are in both collections and then checking if the result is an empty collection.

@issei-m
Copy link
Contributor

issei-m commented Sep 11, 2017

I'm digressing from topic a bit, but in_array without the 3rd argument seems to be scattered in codes.
IMHO, the 3rd argument of in_array should always be true nowadays, and even if we'd pass true to them, that does not make a massive impact in the PHP7 (static-type-hinting) world.

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

3 participants