HH\Lib\Keyset\chunk

Requires the Hack Standard Library to be installed.
Facebook Engineer?

This function is available as Keyset\chunk() in Facebook's www repository.

Returns a vec containing the given Traversable split into chunks of the given size

namespace HH\Lib\Keyset;

function chunk<Tv as arraykey>(
  Traversable<Tv> $traversable,
  int $size,
): vec<keyset<Tv>>;

If the given Traversable doesn't divide evenly, the final chunk will be smaller than the specified size. If there are duplicate values in the Traversable, some chunks may be smaller than the specified size.

Time complexity: O(n) Space complexity: O(n)

Parameters

Returns

  • vec<keyset<Tv>>