HH\Lib\Dict\flip

Meta Engineer?

This is available as Dict\flip in the www repository.

Returns a new dict keyed by the values of the given KeyedTraversable and vice-versa

namespace HH\Lib\Dict;

function flip<Tk, Tv as arraykey>(
  KeyedTraversable<Tk, Tv> $traversable,
): dict<Tv, Tk>;

In case of duplicate values, later keys overwrite the previous ones.

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

Parameters

Returns

  • dict<Tv, Tk>