-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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] Create Collection chunkInto
method
#35295
Conversation
this methods defines the number of chunks we would like to end up with. it fills all non-last chunks first, before placing the remainder in the final chunk.
Can you explain in simple terms how it is fundamentally different than |
On one of our sites, we have a sitemap page with a list of all the pages on the site. I wanted to display them in columns, and I wanted it display like in the second picture. This is where |
chunkInto
methodchunkInto
method
One thing giving me a bit of pause is we have used the "into" language to indicate something will be injected into a class... mapInto and pipeInto for example. |
Gotcha. Yah, I'm totally open to other names. Maybe sticking with the
Another option would be to pass a second parameter flag to |
I think I'm fine with |
forgot the LazyCollection.
*/ | ||
public function splitIn($numberOfGroups) | ||
{ | ||
return $this->chunk(ceil($this->count() / $numberOfGroups)); |
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.
This enumerates the whole collection twice 😢
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.
I'll admit I don't understand the lazy collections as well, so if there's a better way to do this, definitely open to it.
This methods defines the number of chunks we would like to end up with. It fills all non-last chunks first, before placing the remainder in the final chunk.
This method is similar to, but different than,
split()
.Given the following Collection:
$array->split(3)
will return 3 chunks of sizes 4, 3, and 3.$array->chunkInto(3)
will return 3 chunks of sizes 4, 4, and 2.