-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[6.x] Add LazyCollection@remember method #30443
[6.x] Add LazyCollection@remember method #30443
Conversation
54ae1cc
to
903a132
Compare
dd4f7bd
to
3c0afdd
Compare
3c0afdd
to
e720eba
Compare
Just being honest these method names on LazyCollection seem so hard to figure out. When I see "remember" i think it has something to do with Laravel's caching system. |
What about 'keep' or 'retain'? |
Obviously a breaking change but – what about make |
How about just |
partition() ? I love this idea ! |
I like the name "remember" because I can figure out that this is using cache like the functions of cache system |
@tobiasthaden I think that would lead to a lot of confusion, and in my case I would probably write fresh more than remember with the current implementation. @36864 It's an already existing method on the collection so that's not a good solution in my opinion. collect()->lazy()->lazy(); @narwy That's already an [existing method])https://laravel.com/docs/6.x/collections#method-partition) I like the remember, I don't see the reason to use different names in different parts in the software, just like we don't use different methods for dispatching a job or an event. I want cache to remember something: |
I'll add it but I can't say that I understand it, heh. 😬 |
@JosephSilber thanks! Can you also send in a pr to the docs? |
This PR adds a
remember
method to theLazyCollection
class.Calling
remember
returns a new lazy collection that will remember any values that are enumerated, and will not pull it again from the source when it's enumerated again. Here are two examples:Example 1
Example 2
This PR includes extensive tests ensuring that it's fully lazy, and that two simultaneous runners don't step on each other's toes.
The
partition
methodAfter this is merged, I'll rewrite the
partition
method using this.Currently, calling
partition
immediately enumerates the whole collection, since we had no way to create two streams for the same dataset.Now with
remember
, we can get a truly lazy version ofpartition
!