HH\Lib\Vec\chunk
Returns a vec containing the original vec split into chunks of the given size
namespace HH\Lib\Vec;
function chunk<Tv>(
Traversable<Tv> $traversable,
int $size,
): vec<vec<Tv>>;
If the original vec doesn't divide evenly, the final chunk will be smaller.
Time complexity: O(n) Space complexity: O(n)
Parameters
Traversable<Tv>
$traversable
int $size
Returns
vec<vec<Tv>>
Examples
$example_vec = vec[1,2,3,4,5];
$chunks = Vec\chunk($example_vec, 3);
print_r($chunks);
// result [[1,2,3], [4,5]]
$chunks = Vec\chunk($example_vec, 5);
print_r($chunks);
// result [1,2,3,4,5]