BaseVector
abstract class BaseVector extends BaseCollection implements ArrayAccess, IteratorAggregate
Abstract base class to represent arrays / lists / vectors.
It also provides a concrete implementation for ArrayAccess interface.
Traits
Constants
| CB_ZERO_ARG |
|
Properties
| protected array | $items |
Methods
Count how many elements a collection has.
Convert the collection into a PHP array.
Determines if at least an element of the collection satisfies a condition.
Determines if all elements of the collection satisfies a condition.
Create a new collection instance from the specified iterable.
Determine if a collection is empty.
No description
No description
No description
No description
No description
No description
No description
No description
Append all elements of the specified iterable to the current vector.
Append all elements of the specified iterable to the current vector.
Replace a part of the vector by the specified iterable.
Create a new vector by applying a callback on each element of the vector.
Create a new vector by filtering each element of the vector according the return value of the specified callback function.
No description
Allows to map each vector elements into key/value pairs and collect them into a HashMap.
No description
No description
No description
No description
No description
No description
No description
No description
Retrieve an iterator on the elements of the vector.
Details
at line 88
int
count()
Count how many elements a collection has.
at line 182
array
toArray()
Convert the collection into a PHP array.
in
WithCollection at line 15
mixed
first()
No description
in
WithCollection at line 23
mixed
firstOr(mixed $default)
No description
in
WithCollection at line 45
bool
any(callable $callable)
Determines if at least an element of the collection satisfies a condition.
The execution of callbacks stop after a callable returned true.
in
WithCollection at line 78
bool
all(callable $callable)
Determines if all elements of the collection satisfies a condition.
The execution of callbacks stop after a callable returned false.
at line 45
static BaseCollection
from(iterable $items)
Create a new collection instance from the specified iterable.
at line 95
bool
isEmpty()
Determine if a collection is empty.
at line 34
__construct(iterable $items = [])
No description
at line 53
mixed
get(int $key)
No description
at line 61
mixed
getOr(int $key, mixed $defaultValue)
No description
at line 65
BaseVector
set(int $key, mixed $value)
No description
at line 71
BaseVector
unset(int $key)
No description
at line 77
bool
contains(mixed $value)
No description
at line 99
BaseVector
clear()
No description
at line 105
BaseVector
push(mixed $item)
No description
at line 122
BaseVector
append(iterable $iterable)
Append all elements of the specified iterable to the current vector.
If a value already exists, the value is still added as a duplicate.
This method returns the instance itself, so you can use it in fluent pattern.
at line 140
BaseVector
update(iterable $iterable)
Append all elements of the specified iterable to the current vector.
If a value already exists, it is skipped.
This method returns the instance itself, so you can use it in fluent pattern.
at line 159
BaseVector
replace(iterable $iterable, int $offset = 0, int $len = 0)
Replace a part of the vector by the specified iterable.
This method returns the instance itself, so you can use it in fluent pattern.
at line 198
BaseVector
map(callable $callable)
Create a new vector by applying a callback on each element of the vector.
at line 226
BaseVector
filter(callable $callable)
Create a new vector by filtering each element of the vector according the return value of the specified callback function.
Example:
$words = new Vector(["foo", "bar", "quux", "xizzy"]);
$threeLettersWords = $words->filter(
fn(string $word) => strlen($word) === 3
);
// The new vector contains "foo" and "bar".
at line 242
BaseVector
mapKeys(callable $callable)
No description
at line 259
HashMap
mapToHashMap(callable $callable)
Allows to map each vector elements into key/value pairs and collect them into a HashMap.
at line 282
BaseVector
flatMap(callable $callable)
No description
at line 298
BaseVector
filterKeys(callable $callable)
No description
at line 304
Vector
chunk(int $length)
No description
at line 308
BaseVector
slice(int $offset, int $length)
No description
at line 313
OmniString
implode(string $delimiter)
No description
at line 317
Vector
bigrams()
No description
at line 321
Vector
trigrams()
No description
at line 325
Vector
ngrams(int $n)
No description
at line 361
bool
offsetExists(mixed $offset)
No description
at line 367
mixed
offsetGet(mixed $offset)
No description
at line 373
void
offsetSet(mixed $offset, mixed $value)
No description
at line 384
void
offsetUnset(mixed $offset)
No description
at line 402
ArrayIterator
getIterator()
Retrieve an iterator on the elements of the vector.
This iterator also allows unsetting and modifying values and keys while iterating.