HH\Lib\Keyset\map
Returns a new keyset where each value is the result of calling the given function on the original value
namespace HH\Lib\Keyset;
function map<Tv1, Tv2 as arraykey>(
Traversable<Tv1> $traversable,
(function(Tv1): Tv2) $value_func,
): keyset<Tv2>;
Time complexity: O(n * f), where f is the complexity of $value_func
Space complexity: O(n)
Parameters
Traversable<Tv1>
$traversable
(function(Tv1): Tv2) $value_func
Returns
keyset<Tv2>
Examples
$result = Keyset\map(keyset[1,2,3,4], $val ==> $val*2);
print_r($result);
//result: keyset[2,4,6,8]
$result = Keyset\map(keyset[1,2,3,4], $val ==> $val);
print_r($result);
//result: keyset[1,2,3,4]