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 function.
Tests whether all elements in the iterator pass the test implemented by the provided function.
Iterator that filters elements according to a given $predicate. Maintains original keys.
Iterator that transforms values by calling $transformer. Maintains original keys.
Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
Wraps around iterator and caches its keys and values during iteration.
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 58
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.
at line 77
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.
at line 95
static bool
some(iterable $iterable, callable $predicate)
Tests whether at least one element in the iterator passes the test implemented by the provided function.
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.
at line 132
static Generator
filter(iterable $iterable, callable $predicate)
Iterator that filters elements according to a given $predicate. Maintains original keys.
at line 151
static Generator
map(iterable $iterable, callable $transformer)
Iterator that transforms values by calling $transformer. Maintains original keys.
at line 169
static Generator
mapWithKeys(iterable $iterable, callable $transformer)
Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
at line 188
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 191
__construct(Iterator $iterator, array $cache = [])
No description
at line 198
Generator
getIterator()
No description
Traits
Static class.