HH\Pair
Pair is an immutable, fixed-size collection with exactly two elements
(possibly of different types)
HHVM provides a native implementation for this class. The Hack 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, Pairs have reference-like semantics. The elements
of a Pair cannot be mutated (i.e. you can't assign to the elements of a
Pair) though Pairs may contain mutable objects.
Pairs only support integer keys. If a non-integer key is used, an
exception will be thrown.
Pairs support $m[$k] style syntax for getting values by key. Pairs
also support isset($m[$k]) and empty($m[$k]) syntax, and they provide
similar semantics as arrays.
Pair keys are always 0 and 1, respectively.
You may notice that many methods affecting the instace of Pair return an
ImmVector -- Pairs are essentially backed by 2-element ImmVectors.
Guides
Interface Synopsis
namespace HH;
final class Pair implements \ConstVector<mixed> {...}
Public Methods
->__toString(): string
Returns thestringversion of the currentPair, which is"Pair"->at(int $key): mixed
Returns the value at the specified key in the currentPair->concat<Tu super mixed>(Traversable<mixed, Tu> $traversable): ImmVector<mixed, Tu>
Returns anImmVectorthat is the concatenation of the values of the currentPairand the values of the providedTraversable->containsKey<Tu super int>(Tu $key): bool
Checks whether a provided key exists in the currentPair->count(): int
Returns 2; aPairalways has two values->filter((function(mixed): bool) $callback): ImmVector<mixed>
Returns aImmVectorcontaining the values of the currentPairthat meet a supplied condition->filterWithKey((function(int, mixed): bool) $callback): ImmVector<mixed>
Returns anImmVectorcontaining the values of the currentPairthat meet a supplied condition applied to its keys and values->firstKey(): int
Returns the first key in the currentPair->firstValue(): Tv1
Returns the first value in the currentPair->get(int $key): mixed
Returns the value at the specified key in the currentPair->getIterator(): KeyedIterator<int, mixed>
Returns an iterator that points to beginning of the currentPair->immutable(): this
Returns an immutable version of this collection->isEmpty(): bool
Returnsfalse; aPaircannot be empty->items(): Iterable<mixed>
Returns anIterableview of the currentPair->keys(): ImmVector<int>
Returns anImmVectorwith the values being the keys of the currentPair->lastKey(): int
Returns the last key in the currentPair->lastValue(): Tv2
Returns the last value in the currentPair->lazy(): KeyedIterable<int, mixed>
Returns a lazy, access elements only when needed view of the currentPair->linearSearch<Tu super mixed>(mixed $search_value): int
Returns the index of the first element that matches the search value->map<Tu>((function(mixed): Tu) $callback): ImmVector<Tu>
Returns anImmVectorcontaining the values after an operation has been applied to each value in the currentPair->mapWithKey<Tu>((function(int, mixed): Tu) $callback): ImmVector<Tu>
Returns anImmVectorcontaining the values after an operation has been applied to each key and value in the currentPair->skip(int $n): ImmVector<mixed>
Returns anImmVectorcontaining the values after then-th element of the currentPair->skipWhile((function(mixed): bool) $callback): ImmVector<mixed>
Returns anImmVectorcontaining the values of the currentPairstarting after and including the first value that producestruewhen passed to the specified callback->slice(int $start, int $len): ImmVector<mixed>
Returns a subset of the currentPairstarting from a given key up to, but not including, the element at the provided length from the starting key->take(int $n): ImmVector<mixed>
Returns anImmVectorcontaining the firstnvalues of the currentPair->takeWhile((function(mixed): bool) $callback): ImmVector<mixed>
Returns anImmVectorcontaining the values of the currentPairup to but not including the first value that producesfalsewhen passed to the specified callback->toDArray(): darray<int, mixed>->toImmMap(): ImmMap<int, mixed>
Returns an immutable, integer-keyed map (ImmMap) based on the elements of the currentPair->toImmSet(): ImmSet<arraykey, mixed>
Returns an immutable set (ImmSet) with the values of the currentPair->toImmVector(): ImmVector<mixed>
Returns an immutable vector (ImmVector) containing the elements of the currentPair->toKeysArray(): varray<int>
Returns avarraywhose values are the keys from the currentPair->toMap(): Map<int, mixed>
Returns an integer-keyedMapbased on the elements of the currentPair->toSet(): Set<arraykey, mixed>
Returns aSetwith the values of the currentPair->toVArray(): varray->toValuesArray<Tu>(): varray<Tu>
Returns anvarraycontaining the values from the currentPair->toVector(): Vector<mixed>
Returns aVectorcontaining the elements of the currentPair->values(): ImmVector<mixed>
Returns anImmVectorcontaining the values of the currentPair->zip<Tu>(Traversable<Tu> $traversable): ImmVector<Pair<mixed, Tu>>
Returns anImmVectorwhere each element is aPairthat combines each element of the currentPairand the providedTraversable