Wrapper
in package
implements
ArrayAccess, IteratorAggregate, Countable
This class is a wrapper for arrays, so you can chain functions from that library in nice fashion.
Example:
Wrapper::wrap([1,2,3,4,5]) ->all(above(2)) ->drop(1) ->reduce(add(), 0);
You can use _()
function instead of Wrapper::wrap()
;
Tags
Table of Contents
Interfaces
- ArrayAccess
- IteratorAggregate
- Countable
Properties
- $array : array<string|int, mixed>
Methods
- __construct() : mixed
- adjust() : self
- Return copy of an array with replaced element at given index.
- all() : bool
- Returns true if all elements from the array match the predicate, false if there is any which doesn't.
- any() : bool
- Return true if any element matches given predicate.
- append() : self
- Return copy of an array with given element appended at the end.
- concat() : self
- Concat this array with given one (Wrapper may be passed too).
- count() : int
- diff() : self
- Returns difference between this object and given array or wrapper.
- drop() : self
- Return copy but without first `n` elements of the given `input`.
- dropLast() : self
- Return copy but without `n` last elements of the given `input`.
- dropRepeats() : self
- Return copy but without repeating elements.
- filter() : self
- Returns list with only values matching given predicate.
- flatMap() : self
- Applies given function to each element of the array and return new one with the results flatten to single dimension.
- getIterator() : ArrayIterator
- map() : self
- Applies given function to each element of the array and return new one with the results.
- offsetExists() : bool
- offsetGet() : mixed
- offsetSet() : void
- offsetUnset() : void
- reduce() : mixed
- Reduces array to single value using provided callback.
- toArray() : array<string|int, mixed>
- wrap() : self
Properties
$array
private
array<string|int, mixed>
$array
= []
Methods
__construct()
public
__construct([array<string|int, mixed> $array = [] ]) : mixed
Parameters
- $array : array<string|int, mixed> = []
Return values
mixed —adjust()
Return copy of an array with replaced element at given index.
public
adjust(callable $fn, int $idx) : self
Parameters
- $fn : callable
- $idx : int
Tags
Return values
self —all()
Returns true if all elements from the array match the predicate, false if there is any which doesn't.
public
all(callable $fn) : bool
Parameters
- $fn : callable
Tags
Return values
bool —any()
Return true if any element matches given predicate.
public
any(callable $fn) : bool
Parameters
- $fn : callable
Tags
Return values
bool —append()
Return copy of an array with given element appended at the end.
public
append(mixed $item) : self
Parameters
- $item : mixed
Tags
Return values
self —concat()
Concat this array with given one (Wrapper may be passed too).
public
concat(array<string|int, mixed>|Wrapper $array) : self
Parameters
- $array : array<string|int, mixed>|Wrapper
Tags
Return values
self —count()
public
count() : int
Return values
int —diff()
Returns difference between this object and given array or wrapper.
public
diff(array<string|int, mixed>|Wrapper $array) : self
Parameters
- $array : array<string|int, mixed>|Wrapper
Tags
Return values
self —drop()
Return copy but without first `n` elements of the given `input`.
public
drop(int $n) : self
Parameters
- $n : int
Tags
Return values
self —dropLast()
Return copy but without `n` last elements of the given `input`.
public
dropLast(int $n) : self
Parameters
- $n : int
Tags
Return values
self —dropRepeats()
Return copy but without repeating elements.
public
dropRepeats() : self
Tags
Return values
self —filter()
Returns list with only values matching given predicate.
public
filter(callable $fn) : self
Parameters
- $fn : callable
Tags
Return values
self —flatMap()
Applies given function to each element of the array and return new one with the results flatten to single dimension.
public
flatMap(callable $fn) : self
Parameters
- $fn : callable
Tags
Return values
self —getIterator()
public
getIterator() : ArrayIterator
Return values
ArrayIterator —map()
Applies given function to each element of the array and return new one with the results.
public
map(callable $fn) : self
Parameters
- $fn : callable
Tags
Return values
self —offsetExists()
public
offsetExists(mixed $offset) : bool
Parameters
- $offset : mixed
Return values
bool —offsetGet()
public
offsetGet(mixed $offset) : mixed
Parameters
- $offset : mixed
Return values
mixed —offsetSet()
public
offsetSet(mixed $offset, mixed $value) : void
Parameters
- $offset : mixed
- $value : mixed
Return values
void —offsetUnset()
public
offsetUnset(mixed $offset) : void
Parameters
- $offset : mixed
Return values
void —reduce()
Reduces array to single value using provided callback.
public
reduce(callable $fn, mixed $initialValue) : mixed
Parameters
- $fn : callable
- $initialValue : mixed
Tags
Return values
mixed —toArray()
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —wrap()
public
static wrap(array<string|int, mixed> $array) : self
Parameters
- $array : array<string|int, mixed>