Skip to content

ClosureFactoryIteratorAggregate

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

Class ClosureFactoryIteratorAggregate.

Provides an iterator implementation based on a closure factory.

This class allows dynamic generation of iterators using a provided closure. It is particularly useful in scenarios where deferred computation or dynamic iterable generation is needed.

Usage Examples:

Using Generator Function:


Methods

__construct

Initializes the ClosureFactoryIteratorAggregate with a closure.

public __construct(\Closure $factory): mixed

Parameters:

Parameter Type Description
$factory \Closure a function that returns an iterable structure

getIterator

Retrieves the iterator generated by the factory closure.

public getIterator(): \Traversable

This method invokes the provided closure and returns the resulting Traversable instance. Important: If the generator contains a return statement, its return value will not be iterated.

Return Value:

the iterator generated by the factory function


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