-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
add AbstractCollection
abstract class
#270
Conversation
@BusterNeece What do you think of this option ? |
@drupol I don't mind it, but I think you may have combined two of the methodologies I was talking about in a way that isn't particularly necessary. Right now, this PR has both an Since I'd imagine the static analysis tool will have a fit over the current setup, what I'd propose would be something else:
This is how Doctrine does it, and it works extremely well for both ensuring the main classes are final, while giving developers an easy branching-off-of point for their own implementations: https://github.com/doctrine/orm/blob/2.13.x/lib/Doctrine/ORM/Decorator/EntityManagerDecorator.php It also forces that anyone implementing their own won't reference your |
@drupol Also, upon further investigation, I'm not sure that the wrappable class should return instances of the interface, but rather something like |
Definitely, but AFAIK returning |
@drupol |
Right, then it would be only available for PHP 8 :) I'll do the change later in the evening I think. |
I updated the PR, now the Minimal Working Example is: class AAA extends CollectionDecorator
{
}
$decorated = Collection::unfold(static fn (int $a = 0, int $b = 1): array => [$b, $a + $b]);
$c = (new AAA($decorated))->limit(10);
print_r($c->all()); |
@drupol For immutability's sake, you should probably |
Oooh you're right, going to make the changes. |
@drupol Come to think of it, that would prevent anyone from injecting their own constructors into the extended class...may be worthwhile to make a |
ada6b53
to
7139244
Compare
I like this approach better than the one in #268! That being said, I'm still not sure this is actually needed, for the following reason: if anyone wants to add new, useful operations to Collection, then these would be best placed directly in the library and the main class, rather than a custom one. That way everyone benefits from it. If the argument is that "well, this is a very specific business logic operation and doesn't fit into the library itself", then I would say that it shouldn't be in Collection at all (including an extension of it). Also this feels like peak irony: https://github.com/loophp/collection/pull/270/files#diff-d82dd67de25323d8122521b137f07152b743665fe3e8b718f99136cc90c88fa3R24. Feels wrong to introduce something new as "deprecated" and tell people not to use it. |
I like this approach too, but there's a couple of things to discuss:
|
86d388c
to
0806109
Compare
2ea1fff
to
aa73323
Compare
6898863
to
3bbe432
Compare
@AlexandruGG I think it's definitely ready. WDYT? |
3bbe432
to
f1cbbd3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
@drupol Thanks for your persistence in working on this. Glad to see this kind of extensibility in the library :) |
Thanks you guys ! :) Hope this is going to help some people ! |
This PR has been created while discussing with @AlexandruGG
This is an alternate way to provide an abstract collection class:
Minimal Working Example:
This PR:
Related to #268