HH\Set::concat

Returns a Vector that is the concatenation of the values of the current Set and the values of the provided Traversable.

Description

public function concat(
  Traversable<Tu> $traversable,
): Vector<Tu>

Returns a Vector that is the concatenation of the values of the current Set and the values of the provided Traversable.

The values of the provided Traversable is concatenated to the end of the current Set to produce the returned Vector.

Parameters

  • Traversable<Tu> $traversable - The Traversable to concatenate to the current Set.

Return Values

Examples

This example creates new Sets by concatenating other Traversables. Unlike Set::addAll() this method returns a new Set (not a shallow copy).

<?hh

namespace Hack\UserDocumentation\API\Examples\Set\Concat;

$s = Set {'red'};

// Add all the values in a Vector
$s1 = $s->concat(Vector {'green', 'blue'});

// Add all the values in an array
$s2 = $s1->concat(array('yellow', 'purple'));

var_dump($s); // $s contains 'red'
var_dump($s1); // $s1 contains 'red', 'green', 'blue'
var_dump($s2); // $s2 contains 'red', 'green', 'blue', 'yellow', 'purple'
Output
object(HH\Set)#1 (1) {
  string(3) "red"
}
object(HH\Vector)#3 (3) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(4) "blue"
}
object(HH\Vector)#4 (5) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(4) "blue"
  [3]=>
  string(6) "yellow"
  [4]=>
  string(6) "purple"
}