hphp/hack/manual/apis/Classes/HH/ImmMap/index.md
:::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. :::
ImmMap is an immutable Map
HHVM provides a native implementation for this class. The PHP class definition below is not actually used at run time; it is simply provided for the typechecker and for developer reference.
A ImmMap cannot be mutated. No elements can be added or removed from it,
nor can elements be overwritten using assignment (i.e. $c[$k] = $v is
not allowed).
Construct it with a Traversable:
$a = dict['a' => 1, 'b' => 2];
$fm = new ImmMap($a);
or use the literal syntax
$fm = ImmMap {'a' => 1, 'b' => 2};
namespace HH;
final class ImmMap implements \ConstMap<Tk, Tv> {...}
::fromItems(?Traversable<Pair<Tk, Tv>> $iterable): ImmMap<Tk, Tv>ImmMap from the given Traversable, or an empty ImmMap
if null is passed->__construct(?KeyedTraversable<Tk, Tv> $iterable = NULL): voidImmMap from the given KeyedTraversable, or an empty
ImmMap if null is passed->__toString(): stringstring version of the current ImmMap, which is "ImmMap"->at(Tk $key): TvImmMap->concat<Tu super Tv>(Traversable<Tu> $traversable): ImmVector<Tu>ImmMap and the values of the provided Traversable->contains(mixed $key): boolImmMap->containsKey(mixed $key): boolImmMap->count(): intImmMap->differenceByKey(KeyedTraversable<mixed, mixed> $traversable): ImmMap<Tk, Tv>ImmMap with the keys that are in the current ImmMap, but
not in the provided KeyedTraversable->filter((function(Tv): bool) $callback): ImmMap<Tk, Tv>ImmMap containing the values of the current ImmMap that
meet a supplied condition->filterWithKey((function(Tk, Tv): bool) $callback): ImmMap<Tk, Tv>ImmMap containing the values of the current ImmMap that
meet a supplied condition applied to its keys and values->firstKey(): ?TkImmMap->firstValue(): ?TvImmMap->get(Tk $key): ?TvImmMap->getIterator(): KeyedIterator<Tk, Tv>ImmMap->immutable(): ImmMap<Tk, Tv>ImmMap) of the current ImmMap->isEmpty(): boolImmMap is empty->items(): Iterable<Pair<Tk, Tv>>Iterable view of the current ImmMap->keys(): ImmVector<Tk>ImmMap->lastKey(): ?TkImmMap->lastValue(): ?TvImmMap->lazy(): KeyedIterable<Tk, Tv>ImmMap->map<Tu>((function(Tv): Tu) $callback): ImmMap<Tk, Tu>ImmMap after an operation has been applied to each value in
the current ImmMap->mapWithKey<Tu>((function(Tk, Tv): Tu) $callback): ImmMap<Tk, Tu>ImmMap after an operation has been applied to each key and
value in current ImmMap->skip(int $n): ImmMap<Tk, Tv>ImmMap containing the values after the n-th element of the
current ImmMap->skipWhile((function(Tv): bool) $fn): ImmMap<Tk, Tv>ImmMap containing the values of the current ImmMap starting
after and including the first value that produces true when passed to
the specified callback->slice(int $start, int $len): ImmMap<Tk, Tv>ImmMap starting from a given key
location up to, but not including, the element at the provided length from
the starting key location->take(int $n): ImmMap<Tk, Tv>ImmMap containing the first n key/values of the current
ImmMap->takeWhile((function(Tv): bool) $callback): ImmMap<Tk, Tv>ImmMap containing the keys and values of the current ImmMap
up to but not including the first value that produces false when passed
to the specified callback->toDArray(): darray<Tk, Tv>->toImmMap(): ImmMap<Tk, Tv>ImmMap) of the current ImmMap->toImmSet(): ImmSet<Tv>ImmSet) based on the values of the current
ImmMap->toImmVector(): ImmVector<Tv>ImmVector) with the values of the current
ImmMap->toKeysArray(): varray<Tk>array whose values are the keys of the current ImmMap->toMap(): object->toSet(): object->toVArray(): varray<Tv>->toValuesArray(): varray<Tv>array containing the values from the current ImmMap->toVector(): object->values(): ImmVector<Tv>ImmMap->zip<Tu>(Traversable<Tu> $traversable): ImmMap<Tk, Pair<Tv, Tu>>ImmMap where each value is a Pair that combines the value
of the current ImmMap and the provided Traversable