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
.
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
.
Traits
Static class.