HH\Lib\Dict\from_values
Requires the Hack Standard Library to be installed.
Facebook Engineer?
This function is available as Dict\from_values()
in Facebook's www repository.
Returns a new dict keyed by the result of calling the given function on each corresponding value
namespace HH\Lib\Dict;
function from_values<Tk as arraykey, Tv>(
Traversable<Tv> $values,
(function(Tv): Tk) $key_func,
): dict<Tk, Tv>;
In the case of duplicate keys, later values will overwrite the previous ones.
- To create a dict from keys, see
Dict\from_keys()
. - To create a dict from key/value tuples, see
Dict\from_entries()
.
Time complexity: O(n) Space complexity: O(n)
Parameters
Traversable<Tv> $values
(function(Tv): Tk) $key_func
Returns
dict<Tk, Tv>