hphp/hack/manual/apis/Classes/HH/Set/zip.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Throws an exception unless the current Set or the Traversable is
empty
public function zip<Tu>(
Traversable<Tu> $traversable,
): Set<HH\nothing>;
Since Sets only support integers or strings as values, we cannot have
a Pair as a Set value. So in order to avoid an
InvalidArgumentException, either the current Set or the Traversable
must be empty so that we actually return an empty Set.
Traversable<Tu>$traversable - The Traversable to use to combine with the
elements of the current Set.Set<HH\nothing> - The Set that combines the values of the current Set with
the provided Traversable; one of these must be empty or an
exception is thrown.This example shows that zip won't thrown an Exception if at least one of the current Set or the $traversable is empty:
// The $traversable is empty so the result will be empty
$s = Set {'red', 'green', 'blue', 'yellow'};
$zipped = $s->zip(Vector {});
\var_dump($zipped);
// The Set $s is empty so the result will be empty
$s = Set {};
$zipped = $s->zip(Vector {'My Favorite', 'My Second Favorite'});
\var_dump($zipped);
This example shows that zip will throw an Exception if the result is non-empty:
$s = Set {'red', 'green', 'blue', 'yellow'};
$zipped = $s->zip(Vector {'My Favorite', 'My Second Favorite'});
\var_dump($zipped);