HH\Lib\Dict\take
Returns a new dict containing the first $n
entries of the given
KeyedTraversable
namespace HH\Lib\Dict;
function take<Tk as arraykey, Tv>(
KeyedTraversable<Tk, Tv> $traversable,
int $n,
): dict<Tk, Tv>;
To drop the first $n
entries, see Dict\drop()
.
Time complexity: O(n), where n is $n
Space complexity: O(n), where n is $n
Parameters
KeyedTraversable<Tk,
Tv> $traversable
int $n
Returns
dict<Tk, Tv>
Examples
$result = Dict\take(dict[1 => 2, 2 => 4, 3 => 9], 1);
print_r($result);
//dict[1=>2]
$result = Dict\take(dict[], 1);
print_r($result);
//result: dict[]