Iterables
final class Iterables
Utilities for iterables.
Methods
Tests for the presence of value.
Tests for the presence of key.
Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
Tests whether at least one element in the iterator passes the test implemented by the
provided callback with signature function (mixed $value, mixed $key, iterable $iterable): bool
.
Tests whether all elements in the iterator pass the test implemented by the provided function,
which has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
Iterator that filters elements according to a given $predicate. Maintains original keys.
Iterator that transforms values by calling $transformer. Maintains original keys.
Wraps around iterator and caches its keys and values during iteration.
No description
No description
Details
at line 25
static bool
contains(iterable $iterable, mixed $value)
Tests for the presence of value.
at line 39
static bool
containsKey(iterable $iterable, mixed $key)
Tests for the presence of key.
at line 57
static mixed
first(iterable $iterable, callable|null $predicate = null, callable|null $else = null)
Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
The $predicate has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 75
static mixed
firstKey(iterable $iterable, callable|null $predicate = null, callable|null $else = null)
Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
The $predicate has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 94
static bool
some(iterable $iterable, callable $predicate)
Tests whether at least one element in the iterator passes the test implemented by the
provided callback with signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 113
static bool
every(iterable $iterable, callable $predicate)
Tests whether all elements in the iterator pass the test implemented by the provided function,
which has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 133
static Generator
filter(iterable $iterable, callable $predicate)
Iterator that filters elements according to a given $predicate. Maintains original keys.
The callback has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 153
static Generator
map(iterable $iterable, callable $transformer)
Iterator that transforms values by calling $transformer. Maintains original keys.
The callback has the signature function (mixed $value, mixed $key, iterable $iterable): bool
.
at line 169
static iterable
memoize(iterable $iterable)
Wraps around iterator and caches its keys and values during iteration.
This allows the data to be re-iterated multiple times.
at line 172
__construct(iterable $iterable, array $cache = [])
No description
at line 179
Generator
getIterator()
No description
Traits
Static class.