HH\ImmVector
ImmVector
is an immutable Vector
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.
An ImmVector
cannot be mutated. No elements can be added to it or removed
from it, nor can elements be overwritten using assignment (i.e. $c[$k] = $v
is not allowed).
$v = Vector {1, 2, 3};
$fv = $v->toImmVector();
construct it with a Traversable
:
$a = vec[1, 2, 3];
$fv = new ImmVector($a);
or use the literal syntax:
$fv = ImmVector {1, 2, 3};
Guides
Interface Synopsis
namespace HH;
final class ImmVector implements \ConstVector<Tv> {...}
Public Methods
::fromItems(?Traversable<Tv> $iterable): ImmVector<Tv>
Creates anImmVector
from the givenTraversable
, or an emptyImmVector
ifnull
is passed::fromKeysOf<Tk as arraykey>(?KeyedContainer<Tk, mixed> $container): ImmVector<Tk>
Creates anImmVector
from the keys of the specified container->__construct(?Traversable<Tv> $iterable = NULL): void
Creates anImmVector
from the givenTraversable
, or an emptyImmVector
ifnull
is passed->__toString(): string
Returns thestring
version of the currentImmVector
, which is"ImmVector"
->at(int $key): Tv
Returns the value at the specified key in the currentImmVector
->concat<Tu super Tv>(Traversable<Tu> $traversable): ImmVector<Tu>
Returns anImmVector
that is the concatenation of the values of the currentImmVector
and the values of the providedTraversable
->containsKey(mixed $key): bool
Determines if the specified key is in the currentImmVector
->count(): int
Returns the number of elements in the currentImmVector
->filter((function(Tv): bool) $callback): ImmVector<Tv>
Returns aImmVector
containing the values of the currentImmVector
that meet a supplied condition->filterWithKey((function(int, Tv): bool) $callback): ImmVector<Tv>
Returns anImmVector
containing the values of the currentImmVector
that meet a supplied condition applied to its keys and values->firstKey(): ?int
Returns the first key in the currentImmVector
->firstValue(): ?Tv
Returns the first value in the currentImmVector
->get(int $key): ?Tv
Returns the value at the specified key in the currentImmVector
->getIterator(): KeyedIterator<int, Tv>
Returns an iterator that points to beginning of the currentImmVector
->immutable(): ImmVector<Tv>
Returns the currentImmVector
->isEmpty(): bool
Checks if the currentImmVector
is empty->items(): Iterable<Tv>
Returns anIterable
view of the currentImmVector
->keys(): ImmVector<int>
Returns anImmVector
containing the keys, as values, of the currentImmVector
->lastKey(): ?int
Returns the last key in the currentImmVector
->lastValue(): ?Tv
Returns the last value in the currentImmVector
->lazy(): KeyedIterable<int, Tv>
Returns a lazy, access-elements-only-when-needed view of the currentImmVector
->linearSearch(mixed $search_value): int
Returns the index of the first element that matches the search value->map<Tu>((function(Tv): Tu) $callback): ImmVector<Tu>
Returns anImmVector
containing the results of applying an operation to each value in the currentImmVector
->mapWithKey<Tu>((function(int, Tv): Tu) $callback): ImmVector<Tu>
Returns anImmVector
containing the results of applying an operation to each key/value pair in the currentImmVector
->skip(int $n): ImmVector<Tv>
Returns anImmVector
containing the values after the$n
-th element of the currentImmVector
->skipWhile((function(Tv): bool) $fn): ImmVector<Tv>
Returns anImmVector
containing the values of the currentImmVector
starting after and including the first value that producesfalse
when passed to the specified callback->slice(int $start, int $len): ImmVector<Tv>
Returns a subset of the currentImmVector
starting from a given key up to, but not including, the element at the provided length from the starting key->take(int $n): ImmVector<Tv>
Returns anImmVector
containing the first$n
values of the currentImmVector
->takeWhile((function(Tv): bool) $callback): ImmVector<Tv>
Returns anImmVector
containing the values of the currentImmVector
up to but not including the first value that producesfalse
when passed to the specified callback->toDArray(): darray<int, Tv>
->toImmMap(): ImmMap<int, Tv>
Returns an immutable integer-keyed Map (ImmMap
) based on the elements of the currentImmVector
->toImmSet(): ImmSet<Tv>
Returns an immutable Set (ImmSet
) with the values of the currentImmVector
->toImmVector(): ImmVector<Tv>
Returns the currentImmVector
->toKeysArray(): varray<Tv>
Returns anarray
whose values are the keys from the currentImmVector
->toMap(): Map
Returns a Map built from the keys and values of this ImmVector->toSet(): Set
Returns a Set built from the values of this ImmVector->toVArray(): varray<Tv>
Returns a varray built from the values from this ImmVector->toValuesArray(): varray<Tv>
Returns anarray
containing the values from the currentImmVector
->toVector(): Vector
Returns a Vector built from the values of this ImmVector->values(): ImmVector<Tv>
Returns a newImmVector
containing the values of the currentImmVector
; that is, a copy of the currentImmVector
->zip<Tu>(Traversable<Tu> $traversable): ImmVector<Pair<Tv, Tu>>
Returns anImmVector
where each element is aPair
that combines the element of the currentImmVector
and the providedTraversable