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, Pair
s 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 Pair
s may contain mutable objects.
Pair
s only support integer keys. If a non-integer key is used, an
exception will be thrown.
Pair
s support $m[$k]
style syntax for getting values by key. Pair
s
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
-- Pair
s are essentially backed by 2-element ImmVector
s.
Guides
Interface Synopsis
namespace HH;
final class Pair implements \ConstVector<mixed> {...}
Public Methods
->__toString(): string
Returns thestring
version 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 anImmVector
that is the concatenation of the values of the currentPair
and 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; aPair
always has two values->filter((function(mixed): bool) $callback): ImmVector<mixed>
Returns aImmVector
containing the values of the currentPair
that meet a supplied condition->filterWithKey((function(int, mixed): bool) $callback): ImmVector<mixed>
Returns anImmVector
containing the values of the currentPair
that 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
; aPair
cannot be empty->items(): Iterable<mixed>
Returns anIterable
view of the currentPair
->keys(): ImmVector<int>
Returns anImmVector
with 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 anImmVector
containing the values after an operation has been applied to each value in the currentPair
->mapWithKey<Tu>((function(int, mixed): Tu) $callback): ImmVector<Tu>
Returns anImmVector
containing the values after an operation has been applied to each key and value in the currentPair
->skip(int $n): ImmVector<mixed>
Returns anImmVector
containing the values after then
-th element of the currentPair
->skipWhile((function(mixed): bool) $callback): ImmVector<mixed>
Returns anImmVector
containing the values of the currentPair
starting after and including the first value that producestrue
when passed to the specified callback->slice(int $start, int $len): ImmVector<mixed>
Returns a subset of the currentPair
starting 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 anImmVector
containing the firstn
values of the currentPair
->takeWhile((function(mixed): bool) $callback): ImmVector<mixed>
Returns anImmVector
containing the values of the currentPair
up to but not including the first value that producesfalse
when 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 avarray
whose values are the keys from the currentPair
->toMap(): Map<int, mixed>
Returns an integer-keyedMap
based on the elements of the currentPair
->toSet(): Set<arraykey, mixed>
Returns aSet
with the values of the currentPair
->toVArray(): varray
->toValuesArray<Tu>(): varray<Tu>
Returns anvarray
containing the values from the currentPair
->toVector(): Vector<mixed>
Returns aVector
containing the elements of the currentPair
->values(): ImmVector<mixed>
Returns anImmVector
containing the values of the currentPair
->zip<Tu>(Traversable<Tu> $traversable): ImmVector<Pair<mixed, Tu>>
Returns anImmVector
where each element is aPair
that combines each element of the currentPair
and the providedTraversable