HH\Pair::zip

Returns an ImmVector where each element is a Pair that combines each element of the current Pair and the provided Traversable.

Description

public function zip(
  Traversable<Tu> $traversable,
): ImmVector<Pair<mixed,Tu>>

Returns an ImmVector where each element is a Pair that combines each element of the current Pair and the provided Traversable.

If the number of elements of the current Pair are not equal to the number of elements in the Traversable, then only the combined elements up to and including the final element of the one with the least number of elements is included.

Parameters

  • Traversable<Tu> $traversable - The Traversable to use to combine with the elements of the current Pair.

Return Values

Examples

<?hh

namespace Hack\UserDocumentation\API\Examples\Pair\Zip;

$p = Pair {'foo', -1.5};

$labels = Vector {'First Value', 'Second Value'};
$labeled = $p->zip($labels);

foreach ($labeled as list($value, $label)) {
  echo $label.': '.$value."\n";
}
Output
First Value: foo
Second Value: -1.5