HH\Lib\Dict\unique_by

Meta Engineer?

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

Returns a new dict in which each value appears exactly once, where the value's uniqueness is determined by transforming it to a scalar via the given function

namespace HH\Lib\Dict;

function unique_by<Tk as arraykey, Tv, Ts as arraykey>(
  KeyedContainer<Tk, Tv> $container,
  (function(Tv): Ts) $scalar_func,
): dict<Tk, Tv>;

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

For arraykey values, see Dict\unique().

Time complexity: O(n * s), where s is the complexity of $scalar_func Space complexity: O(n)

Parameters

Returns

  • dict<Tk, Tv>