Skip to content

ClosureIteratorIterator

github-actions edited this page Mar 31, 2026 · 3 revisions

Class ClosureIteratorIterator.

An extended IteratorIterator that applies a closure transformation to each element during iteration.

This class allows applying a transformation function dynamically while iterating over an existing Traversable.

Usage Example:


Methods

__construct

Initializes the ClosureIteratorIterator.

public __construct(iterable $iterator, \Closure $closure): mixed

Parameters:

Parameter Type Description
$iterator iterable the underlying iterator to wrap
$closure \Closure the transformation function applied to each element

current

Returns the current transformed element.

public current(): mixed

The closure is applied to the original current element of the iterator.

Return Value:

the transformed element


Inherited methods

count

Counts the number of elements in the iterable.

public count(): int

If the inner iterator implements Countable, it uses that. Otherwise, it counts the elements by iterating through them.

Return Value:

the number of elements in the iterable


Clone this wiki locally