HH\Map::differenceByKey

Description

public function differenceByKey(
  KeyedTraversable<Tk,Tv> $traversable,
): Map<Tk,Tv>

Returns a new Map with the keys that are in the current Map, but not in the provided KeyedTraversable.

Parameters

  • KeyedTraversable<Tk,Tv> $traversable - The KeyedTraversable on which to compare the keys.

Return Values

Examples

This example shows how differenceByKey can be used to get a new Map with some keys excluded:

<?hh

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

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

$m2 = $m->differenceByKey(Set {'red', 'green', 'blue'});

var_dump($m2);
Output
object(HH\Map)#3 (2) {
  ["yellow"]=>
  string(7) "#ffff00"
  ["purple"]=>
  string(7) "#663399"
}