HH\Lib\Vec\unique_by

Meta Engineer?

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

Returns a new vec containing each element of the given Traversable exactly once, where uniqueness is determined by calling the given scalar function on the values

namespace HH\Lib\Vec;

function unique_by<Tv, Ts as arraykey>(
  Traversable<Tv> $traversable,
  (function(Tv): Ts) $scalar_func,
): vec<Tv>;

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

For arraykey elements, see Vec\unique().

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

Parameters

Returns

  • vec<Tv>