final class Iterables

Utilities for iterables.

Methods

static bool
contains(iterable $iterable, mixed $value)

Tests for the presence of value.

static bool
containsKey(iterable $iterable, mixed $key)

Tests for the presence of key.

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.

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.

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.

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.

static Generator
filter(iterable $iterable, callable $predicate)

Iterator that filters elements according to a given $predicate. Maintains original keys.

static Generator
map(iterable $iterable, callable $transformer)

Iterator that transforms values by calling $transformer. Maintains original keys.

Details

at line 25
static bool contains(iterable $iterable, mixed $value)

Tests for the presence of value.

Parameters

iterable $iterable
mixed $value

Return Value

bool

at line 39
static bool containsKey(iterable $iterable, mixed $key)

Tests for the presence of key.

Parameters

iterable $iterable
mixed $key

Return Value

bool

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.

Parameters

iterable $iterable
callable|null $predicate
callable|null $else

Return Value

mixed

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.

Parameters

iterable $iterable
callable|null $predicate
callable|null $else

Return Value

mixed

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.

Parameters

iterable $iterable
callable $predicate

Return Value

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.

Parameters

iterable $iterable
callable $predicate

Return Value

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.

Parameters

iterable $iterable
callable $predicate

Return Value

Generator

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.

Parameters

iterable $iterable
callable $transformer

Return Value

Generator

Traits

Static class.