Meta Engineer?

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

Returns a new vec containing only the elements of the first Traversable that appear in all the other ones

namespace HH\Lib\Vec;

function intersect<Tv as arraykey>(
  Traversable<Tv> $first,
  Traversable<Tv> $second,
  Container<Tv> ...$rest,
): vec<Tv>;

Duplicate values are preserved.

Time complexity: O(n + m), where n is size of $first and m is the combined size of $second plus all the ...$rest Space complexity: O(n), where n is size of $first



  • vec<Tv>