-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[7.x] Add until Collection method #32262
[7.x] Add until Collection method #32262
Conversation
8f859f3
to
127c916
Compare
If accepted, I'd be glad to follow-up with the Higher Order Proxy for |
Curious to see some application examples of when this might be helpful in a typical Laravel app... |
I needed to get a subset of Orders between a certain date and I had a sorted Eloquent collection of them.
Chatted with @adamwathan and @reinink about it. They both hand macros that did something similar, so I figured I'd try to PR it. |
Interesting. Can you share that snippet of code? |
We probably want this on lazy collections too? |
@taylorotwell, unfortunately, it was just a quick script to rebuild some lost order data. So I didn't keep it. However, I ended up doing a Glad to sit on it until I come across another need. @GrahamCampbell, yeah, I think it'd be pretty nice as a Higher Order Proxy too. That way it's easier to pass custom logic. $prs->until->unapproved(); Glad to add it to whatever. Just want to make sure it's merge-worthy first. |
I'm pretty good with it. Do you think there is merit to naming it |
Your call. I only changed it to have the nice single word method name. Also, this stops when the condition is true. Whereas |
OK, that's fine. Let's go ahead and wrap this up then with the HigherOrder support and LazyCollection support. |
1bc80d4
to
54f2137
Compare
@jasonmccreary ping me when you are done with this |
This introduces a new
until
Collection method. It is similar to thetake_while
method in Ruby.While this functionality may be achieved using combinations of the existing Collection methods or with custom logic, the code clarity provided by this single method brings value.
For example:
May simply be written as:
This would be useful as a higher order method as well.