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