Back to Hhvm

ToImmVector

hphp/hack/manual/apis/Classes/HH/Map/toImmVector.md

latest1.4 KB
Original Source

:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::

Returns an immutable vector (ImmVector) with the values of the current Map

Hack
public function toImmVector(): ImmVector<Tv>;

Returns

Examples

This example shows that toImmVector returns an immutable copy of the Map's values. Mutating the Vector of values doesn't affect the original Map and vice-versa.

basic-usage.hack
function expects_immutable(ImmVector<string> $iv): void {
  \var_dump($iv);
}

<<__EntryPoint>>
function basic_usage_main(): void {
  $m = Map {
    'red' => '#ff0000',
    'green' => '#00ff00',
    'blue' => '#0000ff',
    'yellow' => '#ffff00',
  };

  // Get an immutable Vector of $m's values
  $immutable_v = $m->toImmVector();

  // Add a color to the original Map $m
  $m->add(Pair {'purple', '#663399'});

  expects_immutable($immutable_v);
}
<!-- HHAPIDOC -->