[6.0] Add chunkStartingWith and chunkEndingWith collection methods#29672
[6.0] Add chunkStartingWith and chunkEndingWith collection methods#29672JosephSilber wants to merge 1 commit intolaravel:6.0from
chunkStartingWith and chunkEndingWith collection methods#29672Conversation
|
I personally dislike calling a single item a chunk, a chunk to me feels more like a collection of items. For example, array_chunk() returns an array of arrays. Would you be open to calling this |
|
If I'm understanding correctly, this doesn't seem to be referring to the item as a "chuck" but instead "the chunk starts with this item". |
|
Here are 2 alternatives:
I picked Any better ideas? |
|
What if the chunk method was updated to also take a callback? Either specify a number, or let the user decide the chunk splitting logic. Could that work? Edit: The callback is probably a bit too confusing. I tried some rough code and it takes too much brain power to wrap my head around. Why not name the methods collect([1,2,3,4])->chunkStart(function($item) {
return $item === 2;
}); // [1] [2, 3, 4]
collect([1,2,3,4])->chunkEnd(function($item) {
return $item === 2;
}); // [1, 2] [3, 4] |
|
|
Could we pass the current chunk into the callback? for example if we would want to keep the current chunk if the type/name etc. is the same as previous? would return chunks: or maybe we already have something that can achieve that? |
|
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions! If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response. |
These methods let you chunk the collection using a callback.
For example, let's say we're trying to process one of Laravel's log files:
Using
chunkStartingWith, we're returningtruewherever we want to start a new chunk; in this case, when the line starts with something like[2019-08-21 23:54:33].