HH\Lib\Keyset\take

Meta Engineer?

This is available as Keyset\take in the www repository.

Returns a new keyset containing the first $n elements of the given Traversable

namespace HH\Lib\Keyset;

function take<Tv as arraykey>(
  Traversable<Tv> $traversable,
  int $n,
): keyset<Tv>;

If there are duplicate values in the Traversable, the keyset may be shorter than the specified length.

To drop the first $n elements, see Keyset\drop().

Time complexity: O(n), where n is $n Space complexity: O(n), where n is $n

Parameters

Returns

  • keyset<Tv>

Examples

$result = Keyset\take(keyset[1,200, 5], 2);
print_r($result);
//result: keyset[1,200]

$result = Keyset\take(keyset[100,2000,3,4], 0);
print_r($result);
//result: keyset[]