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.

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



  • dict<Tk, Tv>