HH\Vector::concat

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

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

The returned Vector is created from the values of the current Vector, followed by the values of the provided Traversable.

The returned Vector is a new object; the current Vector is unchanged. Future changes to the current Vector will not affect the returned Vector, and future changes to the returned Vector will not affect the current Vector.

Guide

Parameters

Returns

  • Vector<Tu> - A new Vector containing the values from $traversable concatenated to the values from the current Vector.

Examples

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

$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(varray['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'