HH\Vector::immutable

Returns an immutable copy (ImmVector) of the current Vector.

Description

public function immutable(): ImmVector<Tv>

Returns an immutable copy (ImmVector) of the current Vector.

This method is interchangeable with toImmVector().

Return Values

Examples

<?hh

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

$v = Vector {'red', 'green', 'blue', 'yellow'};

function expects_immutable(ImmVector $iv): void {
  var_dump($iv);
}

// Get a deep, immutable copy of $v
$immutable_v = $v->immutable();

expects_immutable($immutable_v);
Output
object(HH\ImmVector)#2 (4) {
  [0]=>
  string(3) "red"
  [1]=>
  string(5) "green"
  [2]=>
  string(4) "blue"
  [3]=>
  string(6) "yellow"
}