For every element in the provided Traversable, stores a value into the current Map associated with each key, overwriting the previous value associated with the key


public function setAll(
  ?KeyedTraversable<Tk,Tv> $it,
): Map<Tk, Tv>;

This method is equivalent to Map::addAll(). If a key to set does not exist in the Map that does exist in the Traversable, it is created. This is inconsistent with, for example, the method Vector::setAll() where if a key is not found, an exception is thrown.

Future changes made to the current Map ARE reflected in the returned Map, and vice-versa.


  • ?KeyedTraversable<Tk,Tv> $it

Return Values


This example shows how setAll() can be used with any KeyedTraversable:


namespace Hack\UserDocumentation\API\Examples\Map\SetAll;

$m = Map {
  'red' => '#ff0000',
  'green' => '#00ff00',
  'blue' => '#0000ff',
  'yellow' => '#ffff00',

// Set the values at keys 'red' and 'green'
$m->setAll(Map {
  'red' => 'rgb(255, 0, 0)',
  'green' => 'rgb(0, 255, 0)',

// Set the values at keys 'blue' and 'yellow' with an associative array
  'blue' => 'rgb(0, 0, 255)',
  'yellow' => 'rgb(255, 255, 0)',

object(HH\Map)#1 (4) {
  string(14) "rgb(255, 0, 0)"
  string(14) "rgb(0, 255, 0)"
  string(14) "rgb(0, 0, 255)"
  string(16) "rgb(255, 255, 0)"