HH\Map
Map is an ordered dictionary-style collection
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.
Like all objects in PHP, Maps have reference-like semantics. When a caller
passes a Map to a callee, the callee can modify the Map and the caller
will see the changes. Maps do not have "copy-on-write" semantics.
Maps preserve insertion order of key/value pairs. When iterating over a
Map, the key/value pairs appear in the order they were inserted. Also,
Maps do not automagically convert integer-like string keys (ex. "123")
into integer keys.
Maps only support int keys and string keys. If a key of a different
type is used, an exception will be thrown.
Maps support $m[$k] style syntax for getting and setting values by key.
Maps also support isset($m[$k]) and empty($m[$k]) syntax, and they
provide similar semantics as arrays. Adding an element with square bracket
syntax [] is supported either by providing a key between the brackets or
a Pair on the right-hand side. e.g.,
$m[$k] = $v is supported
$m[] = Pair {$k, $v} is supported
$m[] = $v is not supported.
Maps do not support iterating while new keys are being added or elements
are being removed. When a new key is added or an element is removed, all
iterators that point to the Map shall be considered invalid.
Guides
Interface Synopsis
namespace HH;
final class Map implements \MutableMap<Tk, Tv> {...}
Public Methods
::fromArray(darray<Tk, Tv> $arr): Map<Tk, Tv>
Returns aMapcontaining the key/value pairs from the specifiedarray::fromItems(?Traversable<Pair<Tk, Tv>> $iterable): Map<Tk, Tv>
Creates aMapfrom the givenTraversable, or an emptyMapifnullis passed->__construct(?KeyedTraversable<Tk, Tv> $iterable = NULL): void
Creates aMapfrom the givenKeyedTraversable, or an emptyMapifnullis passed->__toString(): string
Returns thestringversion of the currentMap, which is"Map"->add(Pair<Tk, Tv> $val): Map<Tk, Tv>
Add a key/value pair to the end of the currentMap->addAll(?Traversable<Pair<Tk, Tv>> $iterable): Map<Tk, Tv>
For every element in the providedTraversable, add a key/value pair into the currentMap->at(Tk $key): Tv
Returns the value at the specified key in the currentMap->clear(): Map<Tk, Tv>
Remove all the elements from the currentMap->concat<Tu super Tv>(Traversable<Tu> $traversable): Vector<Tu>
Returns aVectorthat is the concatenation of the values of the currentMapand the values of the providedTraversable->contains(mixed $key): bool
Determines if the specified key is in the currentMap->containsKey(mixed $key): bool
Determines if the specified key is in the currentMap->count(): int
Provides the number of elements in the currentMap->differenceByKey(KeyedTraversable<Tk, Tv> $traversable): Map<Tk, Tv>
Returns a newMapwith the keys that are in the currentMap, but not in the providedKeyedTraversable->filter((function(Tv): bool) $callback): Map<Tk, Tv>
Returns aMapcontaining the values of the currentMapthat meet a supplied condition->filterWithKey((function(Tk, Tv): bool) $callback): Map<Tk, Tv>
Returns aMapcontaining the values of the currentMapthat meet a supplied condition applied to its keys and values->firstKey(): ?Tk
Returns the first key in the currentMap->firstValue(): ?Tv
Returns the first value in the currentMap->get(Tk $key): ?Tv
Returns the value at the specified key in the currentMap->getIterator(): KeyedIterator<Tk, Tv>
Returns an iterator that points to beginning of the currentMap->immutable(): ImmMap<Tk, Tv>
Returns a deep, immutable copy (ImmMap) of thisMap->isEmpty(): bool
Checks if the currentMapis empty->items(): Iterable<Pair<Tk, Tv>>
Returns anIterableview of the currentMap->keys(): Vector<Tk>
Returns aVectorcontaining the keys of the currentMap->lastKey(): ?Tk
Returns the last key in the currentMap->lastValue(): ?Tv
Returns the last value in the currentMap->lazy(): KeyedIterable<Tk, Tv>
Returns a lazy, access elements only when needed view of the currentMap->map<Tu>((function(Tv): Tu) $callback): Map<Tk, Tu>
Returns aMapafter an operation has been applied to each value in the currentMap->mapWithKey<Tu>((function(Tk, Tv): Tu) $callback): Map<Tk, Tu>
Returns aMapafter an operation has been applied to each key and value in the currentMap->remove(Tk $key): Map<Tk, Tv>
Removes the specified key (and associated value) from the currentMap->removeKey(Tk $key): Map<Tk, Tv>
Removes the specified key (and associated value) from the currentMap->reserve(int $sz): void
Reserves enough memory to accommodate a given number of elements->retain(mixed $callback): Map
Ensures that this Map contains only keys/values for which the specified callback returns true when passed the value->retainWithKey(mixed $callback): Map
Ensures that this Map contains only keys/values for which the specified callback returns true when passed the key and the value->set(Tk $key, Tv $value): Map<Tk, Tv>
Stores a value into the currentMapwith the specified key, overwriting the previous value associated with the key->setAll(?KeyedTraversable<Tk, Tv> $iterable): Map<Tk, Tv>
For every element in the providedTraversable, stores a value into the currentMapassociated with each key, overwriting the previous value associated with the key->skip(int $n): Map<Tk, Tv>
Returns aMapcontaining the values after then-th element of the currentMap->skipWhile((function(Tv): bool) $fn): Map<Tk, Tv>
Returns aMapcontaining the values of the currentMapstarting after and including the first value that producestruewhen passed to the specified callback->slice(int $start, int $len): Map<Tk, Tv>
Returns a subset of the currentMapstarting from a given key location up to, but not including, the element at the provided length from the starting key location->take(int $n): Map<Tk, Tv>
Returns aMapcontaining the firstnkey/values of the currentMap->takeWhile((function(Tv): bool) $callback): Map<Tk, Tv>
Returns aMapcontaining the keys and values of the currentMapup to but not including the first value that producesfalsewhen passed to the specified callback->toDArray(): darray<Tk, Tv>
Returns a darray built from the keys and values from this Map->toImmMap(): ImmMap<Tk, Tv>
Returns a deep, immutable copy (ImmMap) of the currentMap->toImmSet(): ImmSet<Tv>
Returns an immutable set (ImmSet) based on the values of the currentMap->toImmVector(): ImmVector<Tv>
Returns an immutable vector (ImmVector) with the values of the currentMap->toKeysArray(): varray<Tk>
Returns anarraywhose values are the keys of the currentMap->toMap(): Map<Tk, Tv>
Returns a deep copy of the currentMap->toSet(): Set<Tv>
Returns aSetbased on the values of the currentMap->toVArray(): varray<Tv>->toValuesArray(): varray<Tv>
Returns anarraycontaining the values from the currentMap->toVector(): Vector<Tv>
Returns aVectorwith the values of the currentMap->values(): Vector<Tv>
Returns aVectorcontaining the values of the currentMap->zip<Tu>(Traversable<Tu> $traversable): Map<Tk, Pair<Tv, Tu>>
Returns aMapwhere each value is aPairthat combines the value of the currentMapand the providedTraversable