HH\ImmMap
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};
Guides
Interface Synopsis
namespace HH;
final class ImmMap implements \ConstMap<Tk, Tv> {...}
Public Methods
::fromItems(?Traversable<Pair<Tk, Tv>> $iterable): ImmMap<Tk, Tv>
Creates anImmMap
from the givenTraversable
, or an emptyImmMap
ifnull
is passed->__construct(?KeyedTraversable<Tk, Tv> $iterable = NULL): void
Creates anImmMap
from the givenKeyedTraversable
, or an emptyImmMap
ifnull
is passed->__toString(): string
Returns thestring
version of the currentImmMap
, which is"ImmMap"
->at(Tk $key): Tv
Returns the value at the specified key in the currentImmMap
->concat<Tu super Tv>(Traversable<Tu> $traversable): ImmVector<Tu>
Returns an ImmVector that is the concatenation of the values of the currentImmMap
and the values of the providedTraversable
->contains(mixed $key): bool
Determines if the specified key is in the currentImmMap
->containsKey(mixed $key): bool
Determines if the specified key is in the currentImmMap
->count(): int
Provides the number of elements in the currentImmMap
->differenceByKey(KeyedTraversable<mixed, mixed> $traversable): ImmMap<Tk, Tv>
Returns a newImmMap
with the keys that are in the currentImmMap
, but not in the providedKeyedTraversable
->filter((function(Tv): bool) $callback): ImmMap<Tk, Tv>
Returns anImmMap
containing the values of the currentImmMap
that meet a supplied condition->filterWithKey((function(Tk, Tv): bool) $callback): ImmMap<Tk, Tv>
Returns anImmMap
containing the values of the currentImmMap
that meet a supplied condition applied to its keys and values->firstKey(): ?Tk
Returns the first key in the currentImmMap
->firstValue(): ?Tv
Returns the first value in the currentImmMap
->get(Tk $key): ?Tv
Returns the value at the specified key in the currentImmMap
->getIterator(): KeyedIterator<Tk, Tv>
Returns an iterator that points to beginning of the currentImmMap
->immutable(): ImmMap<Tk, Tv>
Returns an immutable copy (ImmMap
) of the currentImmMap
->isEmpty(): bool
Checks if the currentImmMap
is empty->items(): Iterable<Pair<Tk, Tv>>
Returns anIterable
view of the currentImmMap
->keys(): ImmVector<Tk>
Returns an ImmVector containing, as values, the keys of the currentImmMap
->lastKey(): ?Tk
Returns the last key in the currentImmMap
->lastValue(): ?Tv
Returns the last value in the currentImmMap
->lazy(): KeyedIterable<Tk, Tv>
Returns a lazy, access elements only when needed view of the currentImmMap
->map<Tu>((function(Tv): Tu) $callback): ImmMap<Tk, Tu>
Returns anImmMap
after an operation has been applied to each value in the currentImmMap
->mapWithKey<Tu>((function(Tk, Tv): Tu) $callback): ImmMap<Tk, Tu>
Returns anImmMap
after an operation has been applied to each key and value in currentImmMap
->skip(int $n): ImmMap<Tk, Tv>
Returns anImmMap
containing the values after then
-th element of the currentImmMap
->skipWhile((function(Tv): bool) $fn): ImmMap<Tk, Tv>
Returns anImmMap
containing the values of the currentImmMap
starting after and including the first value that producestrue
when passed to the specified callback->slice(int $start, int $len): ImmMap<Tk, Tv>
Returns a subset of the currentImmMap
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>
Returns anImmMap
containing the firstn
key/values of the currentImmMap
->takeWhile((function(Tv): bool) $callback): ImmMap<Tk, Tv>
Returns anImmMap
containing the keys and values of the currentImmMap
up to but not including the first value that producesfalse
when passed to the specified callback->toDArray(): darray<Tk, Tv>
Returns a darray built from the keys and values from this ImmMap->toImmMap(): ImmMap<Tk, Tv>
Returns an immutable copy (ImmMap
) of the currentImmMap
->toImmSet(): ImmSet<Tv>
Returns an immutable set (ImmSet
) based on the values of the currentImmMap
->toImmVector(): ImmVector<Tv>
Returns an immutable vector (ImmVector
) with the values of the currentImmMap
->toKeysArray(): varray<Tk>
Returns anarray
whose values are the keys of the currentImmMap
->toMap(): object
Returns a Map built from the keys and values of this ImmMap->toSet(): object
Returns a Set built from the values of this ImmMap->toVArray(): varray<Tv>
->toValuesArray(): varray<Tv>
Returns anarray
containing the values from the currentImmMap
->toVector(): object
Returns a Vector built from the values of this ImmMap->values(): ImmVector<Tv>
Returns an ImmVector containing the values of the currentImmMap
->zip<Tu>(Traversable<Tu> $traversable): ImmMap<Tk, Pair<Tv, Tu>>
Returns anImmMap
where each value is aPair
that combines the value of the currentImmMap
and the providedTraversable