File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ This package provides functions to work with [iterables](https://wiki.php.net/rf
16
16
- [ iterable_reduce()] ( #iterable_reduce )
17
17
- [ iterable_filter()] ( #iterable_filter )
18
18
- [ iterable_values()] ( #iterable_values )
19
+ - [ iterable_chunk()] ( #iterable_chunk )
19
20
20
21
iterable_to_array()
21
22
-------------------
@@ -170,6 +171,33 @@ foreach (iterable_values($generator()) as $key => $value) {
170
171
}
171
172
```
172
173
174
+ iterable_chunk()
175
+ --------------
176
+
177
+ Here's an ` array_chunk ` -like function that also works with a ` Traversable ` .
178
+
179
+ ``` php
180
+ use function BenTools\IterableFunctions\iterable_chunk;
181
+
182
+ $fruits = [
183
+ 'banana',
184
+ 'apple',
185
+ 'strawberry',
186
+ 'raspberry',
187
+ 'pineapple',
188
+ ]
189
+ $fruits = (fn () => yield from $fruits)()
190
+ iterable_chunk($fruits, 2);
191
+
192
+ /*
193
+ [
194
+ ['banana', 'apple'],
195
+ ['strawberry', 'raspberry'],
196
+ ['pineapple'],
197
+ ]
198
+ */
199
+ ```
200
+
173
201
Iterable fluent interface
174
202
=========================
175
203
You can’t perform that action at this time.
0 commit comments