Iterables
in package
uses
StaticClass
Utilities for iterables.
Table of Contents
Methods
- contains() : bool
- Tests for the presence of value.
- containsKey() : bool
- Tests for the presence of key.
- every() : bool
- Tests whether all elements in the iterator pass the test implemented by the provided function.
- filter() : Generator<K, V>
- Iterator that filters elements according to a given $predicate. Maintains original keys.
- first() : V|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.
- firstKey() : K|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.
- map() : Generator<K, R>
- Iterator that transforms values by calling $transformer. Maintains original keys.
- mapWithKeys() : Generator<ResV, ResK>
- Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
- memoize() : IteratorAggregate<K, V>
- Wraps around iterator and caches its keys and values during iteration.
- repeatable() : IteratorAggregate<K, V>
- Creates a repeatable iterator from a factory function.
- some() : bool
- Tests whether at least one element in the iterator passes the test implemented by the provided function.
- toIterator() : Iterator<K, V>
- Creates an iterator from anything that is iterable.
- __construct() : mixed
- Class is static and cannot be instantiated.
Methods
contains()
Tests for the presence of value.
public
static contains(iterable<string|int, mixed> $iterable, mixed $value) : bool
Parameters
- $iterable : iterable<string|int, mixed>
- $value : mixed
Return values
boolcontainsKey()
Tests for the presence of key.
public
static containsKey(iterable<string|int, mixed> $iterable, mixed $key) : bool
Parameters
- $iterable : iterable<string|int, mixed>
- $key : mixed
Return values
boolevery()
Tests whether all elements in the iterator pass the test implemented by the provided function.
public
static every(iterable<K, V> $iterable, callable(V, K, iterable<K, V>): bool $predicate) : bool
Parameters
- $iterable : iterable<K, V>
- $predicate : callable(V, K, iterable<K, V>): bool
Tags
Return values
boolfilter()
Iterator that filters elements according to a given $predicate. Maintains original keys.
public
static filter(iterable<K, V> $iterable, callable(V, K, iterable<K, V>): bool $predicate) : Generator<K, V>
Parameters
- $iterable : iterable<K, V>
- $predicate : callable(V, K, iterable<K, V>): bool
Tags
Return values
Generator<K, V>first()
Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
public
static first(iterable<K, V> $iterable[, callable(V, K, iterable<K, V>): bool|null $predicate = null ][, callable|null $else = null ]) : V|null
Parameters
- $iterable : iterable<K, V>
- $predicate : callable(V, K, iterable<K, V>): bool|null = null
- $else : callable|null = null
Tags
Return values
V|nullfirstKey()
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.
public
static firstKey(iterable<K, V> $iterable[, callable(V, K, iterable<K, V>): bool|null $predicate = null ][, callable|null $else = null ]) : K|null
Parameters
- $iterable : iterable<K, V>
- $predicate : callable(V, K, iterable<K, V>): bool|null = null
- $else : callable|null = null
Tags
Return values
K|nullmap()
Iterator that transforms values by calling $transformer. Maintains original keys.
public
static map(iterable<K, V> $iterable, callable(V, K, iterable<K, V>): R $transformer) : Generator<K, R>
Parameters
- $iterable : iterable<K, V>
- $transformer : callable(V, K, iterable<K, V>): R
Tags
Return values
Generator<K, R>mapWithKeys()
Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
public
static mapWithKeys(iterable<K, V> $iterable,
Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78
callable(V, K, iterable<K, V>): Array $transformer) : Generator<ResV, ResK>
Parameters
- $iterable : iterable<K, V>
- $transformer : Warning: Array to string conversion in C:\xampp\htdocs\vendor\phpdocumentor\phpdocumentor\src\phpDocumentor\Transformer\Writer\Twig\LinkRenderer\CallableAdapter.php on line 78 callable(V, K, iterable<K, V>): Array
Tags
Return values
Generator<ResV, ResK>memoize()
Wraps around iterator and caches its keys and values during iteration.
public
static memoize(iterable<K, V> $iterable) : IteratorAggregate<K, V>
This allows the data to be re-iterated multiple times.
Parameters
- $iterable : iterable<K, V>
Tags
Return values
IteratorAggregate<K, V>repeatable()
Creates a repeatable iterator from a factory function.
public
static repeatable(callable(): iterable<K, V> $factory) : IteratorAggregate<K, V>
The factory is called every time the iterator is iterated.
Parameters
- $factory : callable(): iterable<K, V>
Tags
Return values
IteratorAggregate<K, V>some()
Tests whether at least one element in the iterator passes the test implemented by the provided function.
public
static some(iterable<K, V> $iterable, callable(V, K, iterable<K, V>): bool $predicate) : bool
Parameters
- $iterable : iterable<K, V>
- $predicate : callable(V, K, iterable<K, V>): bool
Tags
Return values
booltoIterator()
Creates an iterator from anything that is iterable.
public
static toIterator(iterable<K, V> $iterable) : Iterator<K, V>
Parameters
- $iterable : iterable<K, V>
Tags
Return values
Iterator<K, V>__construct()
Class is static and cannot be instantiated.
private
__construct() : mixed