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 function.

static bool
every(iterable $iterable, callable $predicate)

Tests whether all elements in the iterator pass the test implemented by the provided function.

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.

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

Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.

static iterable
memoize(iterable $iterable)

Wraps around iterator and caches its keys and values during iteration.

__construct(Iterator $iterator, array $cache = [])

No description

getIterator()

No description

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 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.

Parameters

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

Return Value

mixed

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.

Parameters

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

Return Value

mixed

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.

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.

Parameters

iterable $iterable
callable $predicate

Return Value

bool

at line 132
static Generator filter(iterable $iterable, callable $predicate)

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

Parameters

iterable $iterable
callable $predicate

Return Value

Generator

at line 151
static Generator map(iterable $iterable, callable $transformer)

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

Parameters

iterable $iterable
callable $transformer

Return Value

Generator

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.

Parameters

iterable $iterable
callable $transformer

Return Value

Generator

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.

Parameters

iterable $iterable

Return Value

iterable

at line 191
__construct(Iterator $iterator, array $cache = [])

No description

Parameters

Iterator $iterator
array $cache

at line 198
Generator getIterator()

No description

Return Value

Generator

Traits

Static class.