@@ -78,6 +78,7 @@ For the remainder of this documentation, we'll discuss each method available on
7878[ average] ( #method-average )
7979[ avg] ( #method-avg )
8080[ chunk] ( #method-chunk )
81+ [ chunkWhile] ( #method-chunkwhile )
8182[ collapse] ( #method-collapse )
8283[ collect] ( #method-collect )
8384[ combine] ( #method-combine )
@@ -263,6 +264,21 @@ This method is especially useful in [views](/docs/{{version}}/views) when workin
263264 </div>
264265 @endforeach
265266
267+ <a name =" method-chunkwhile " ></a >
268+ #### ` chunkWhile() ` {#collection-method}
269+
270+ The ` chunkWhile ` method breaks the collection into multiple, smaller collections based on the evaluation of the given callback:
271+
272+ $collection = collect(str_split('AABBCCCD'));
273+
274+ $chunks = $collection->chunkWhile(function($current, $key, $chunk) {
275+ return $current === $chunk->last();
276+ });
277+
278+ $chunks->toArray();
279+
280+ // [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]
281+
266282<a name =" method-collapse " ></a >
267283#### ` collapse() ` {#collection-method}
268284
@@ -2746,6 +2762,7 @@ Almost all methods available on the `Collection` class are also available on the
27462762[ average] ( #method-average )
27472763[ avg] ( #method-avg )
27482764[ chunk] ( #method-chunk )
2765+ [ chunkWhile] ( #method-chunkwhile )
27492766[ collapse] ( #method-collapse )
27502767[ collect] ( #method-collect )
27512768[ combine] ( #method-combine )
0 commit comments