HH\Pair::map

Returns an ImmVector containing the values after an operation has been applied to each value in the current Pair

public function map<Tu>(
  (function(mixed): Tu) $callback,
): ImmVector<Tu>;

Every value in the current Pair is affected by a call to map(), unlike filter() where only values that meet a certain criteria are affected.

Guide

Parameters

  • (function(mixed): Tu) $callback - The callback containing the operation to apply to the current Pair values.

Returns

Examples

In this example the Pair's values are mapped to 0 if they're NULL:

$p = Pair {null, -1.5};

$immutable_v = $p->map($value ==> {
  if ($value === null) {
    return 0;
  }
  return $value;
});
\var_dump($immutable_v);