HH\Vector::concat

Returns a Vector that is the concatenation of the values of the current Vector 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 Vector and the values of the provided Traversable.

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

Parameters

Return Values

Examples

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

<?hh

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

$v = Vector {'red'};

// Add all the values in a Set
$v1 = $v->concat(Set {'green', 'blue'});

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

var_dump($v); // $v contains 'red'
var_dump($v1); // $v1 contains 'red', 'green', 'blue'
var_dump($v2); // $v2 contains 'red', 'green', 'blue', 'yellow', 'purple'
Output
object(HH\Vector)#1 (1) {
  [0]=>
  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"
}