Deque
class Deque implements Sequence (View source)
Methods
Creates a new instance, using either a traversable object or an array for the initial values.
Count elements of an object
Removes all values from the deque.
Returns a shallow copy of the deque.
No description
Returns whether the deque is empty.
Converts the deque to an array.
Ensures that enough memory is allocated for a required capacity.
Updates all values by applying a callback function to each value in the deque.
Returns the current capacity.
Determines if the deque contains all values.
Creates a new deque using a callable to determine which values to include.
Returns the index of the value, or FALSE if not found.
Returns the first value in the deque.
Returns the value at a given index.
Inserts values into the deque at a given index.
Joins all values together as a string using an optional separator between each value.
Returns the last value in the deque.
Returns the result of applying a callback function to each value in the deque.
Removes and returns the last value.
Adds values to the end of the deque.
Reduces the deque to a single value using a callback function.
Removes and returns a value by index.
Reverses the deque in-place.
Returns a reversed copy of the deque.
Rotates the deque by a given number of rotations, which is equivalent to successively calling $deque->push($deque->shift()) if the number of rotations is positive, or $deque->unshift($deque->pop()) if negative.
Updates a value at a given index.
Removes and returns the first value.
Creates a sub-deque of a given range.
Sorts the deque in-place, using an optional comparator function.
Returns a sorted copy, using an optional comparator function.
Returns the sum of all values in the deque.
Adds values to the front of the deque, moving all the current values forward to make room for the new values.
Specify data which should be serialized to JSON
No description
No description
No description
No description
Details
__construct(TValue ...$values)
Creates a new instance, using either a traversable object or an array for the initial values.
int
count()
Count elements of an object
void
clear()
Removes all values from the deque.
TValue>
copy()
Returns a shallow copy of the deque.
Traversable
getIterator()
No description
bool
isEmpty()
Returns whether the deque is empty.
array
toArray()
Converts the deque to an array.
Note: Casting to an array is not supported yet.
void
allocate(int $capacity)
Ensures that enough memory is allocated for a required capacity.
This removes the need to reallocate the internal as values are added.
void
apply(callable $callback)
Updates all values by applying a callback function to each value in the deque.
int
capacity()
Returns the current capacity.
bool
contains(TValue ...$values)
Determines if the deque contains all values.
TValue>
filter(callable|null $callback = null)
Creates a new deque using a callable to determine which values to include.
int|false
find(TValue $value)
Returns the index of the value, or FALSE if not found.
TValue
first()
Returns the first value in the deque.
TValue
get(int $index)
Returns the value at a given index.
void
insert(int $index, TValue ...$values)
Inserts values into the deque at a given index.
string
join(string $glue = '')
Joins all values together as a string using an optional separator between each value.
TValue
last()
Returns the last value in the deque.
Sequence
map(callable $callback)
Returns the result of applying a callback function to each value in the deque.
Sequence
merge(TValue2> $values)
Returns the result of adding all given values to the deque.
TValue
pop()
Removes and returns the last value.
void
push(TValue ...$values)
Adds values to the end of the deque.
TCarry
reduce(callable $callback, TCarry $initial = null)
Reduces the deque to a single value using a callback function.
TValue
remove(int $index)
Removes and returns a value by index.
void
reverse()
Reverses the deque in-place.
TValue>
reversed()
Returns a reversed copy of the deque.
void
rotate(int $rotations)
Rotates the deque by a given number of rotations, which is equivalent to successively calling $deque->push($deque->shift()) if the number of rotations is positive, or $deque->unshift($deque->pop()) if negative.
void
set(int $index, TValue $value)
Updates a value at a given index.
TValue
shift()
Removes and returns the first value.
TValue>
slice(int $index, int $length = null)
Creates a sub-deque of a given range.
void
sort(callable|null $comparator = null)
Sorts the deque in-place, using an optional comparator function.
TValue>
sorted(callable|null $comparator = null)
Returns a sorted copy, using an optional comparator function.
float|int
sum()
Returns the sum of all values in the deque.
Note: Arrays and objects are considered equal to zero when calculating the sum.
void
unshift(TValue ...$values)
Adds values to the front of the deque, moving all the current values forward to make room for the new values.
mixed
jsonSerialize()
Specify data which should be serialized to JSON
bool
offsetExists(TKey $offset)
No description
mixed
offsetGet(TKey $offset)
No description
void
offsetSet(TKey $offset, TValue $value)
No description
void
offsetUnset(TKey $offset)
No description