Vector
class Vector extends BaseVector
A generic vector implementation to accept any kind of value.
Vector offers specialized methods to convert from and to int/string.
This class is intended to be used in every case a more specialized vector implementation doesn't exist or isn't needed, ie every time an array is needed, to contains ordered values, without string keys.
Traits
Constants
| CB_ZERO_ARG |
|
Properties
| protected array | $items | from BaseVector |
Methods
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.
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.
Allows to map each vector elements into key/value pairs and collect them into a HashMap.
Constructs a new instance of a vector by exploding a string according a specified delimiter.
No description
Details
in
WithCollection at line 12
abstract int
count()
No description
in
WithCollection at line 13
abstract array
toArray()
No description
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.
in
BaseVector at line 45
static BaseCollection
from(iterable $items)
Create a new collection instance from the specified iterable.
in
BaseVector at line 95
bool
isEmpty()
Determine if a collection is empty.
in
BaseVector at line 34
__construct(iterable $items = [])
No description
in
BaseVector at line 53
mixed
get(int $key)
No description
in
BaseVector at line 61
mixed
getOr(int $key, mixed $defaultValue)
No description
in
BaseVector at line 65
BaseVector
set(int $key, mixed $value)
No description
in
BaseVector at line 71
BaseVector
unset(int $key)
No description
in
BaseVector at line 77
bool
contains(mixed $value)
No description
in
BaseVector at line 99
BaseVector
clear()
No description
in
BaseVector at line 105
BaseVector
push(mixed $item)
No description
in
BaseVector 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.
in
BaseVector 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.
in
BaseVector 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.
in
BaseVector at line 198
BaseVector
map(callable $callable)
Create a new vector by applying a callback on each element of the vector.
in
BaseVector 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".
in
BaseVector at line 242
BaseVector
mapKeys(callable $callable)
No description
in
BaseVector at line 259
HashMap
mapToHashMap(callable $callable)
Allows to map each vector elements into key/value pairs and collect them into a HashMap.
in
BaseVector at line 282
BaseVector
flatMap(callable $callable)
No description
in
BaseVector at line 298
BaseVector
filterKeys(callable $callable)
No description
in
BaseVector at line 304
Vector
chunk(int $length)
No description
in
BaseVector at line 308
BaseVector
slice(int $offset, int $length)
No description
in
BaseVector at line 313
OmniString
implode(string $delimiter)
No description
in
BaseVector at line 317
Vector
bigrams()
No description
in
BaseVector at line 321
Vector
trigrams()
No description
in
BaseVector at line 325
Vector
ngrams(int $n)
No description
in
BaseVector at line 361
bool
offsetExists(mixed $offset)
No description
in
BaseVector at line 367
mixed
offsetGet(mixed $offset)
No description
in
BaseVector at line 373
void
offsetSet(mixed $offset, mixed $value)
No description
in
BaseVector at line 384
void
offsetUnset(mixed $offset)
No description
in
BaseVector 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.
at line 32
static Vector
explode(string $delimiter, string $string, int $limit = PHP_INT_MAX)
Constructs a new instance of a vector by exploding a string according a specified delimiter.
at line 49
static Vector
range(int $start, int $end, int $step = 1)
No description
at line 57
Vector
toIntegers()
No description