-
-
Notifications
You must be signed in to change notification settings - Fork 0
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.
- Full name:
\FastForward\Iterator\ClosureFactoryIteratorAggregate - Parent class:
\FastForward\Iterator\CountableIteratorAggregate
Initializes the ClosureFactoryIteratorAggregate with a closure.
public __construct(\Closure $factory): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$factory |
\Closure | a function that returns an iterable structure |
Retrieves the iterator generated by the factory closure.
public getIterator(): \TraversableThis 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
Counts the number of elements exposed by the inner iterator.
public count(): intIf the inner iterator implements
-
See: \Countable, this method SHALL return the value provided by that implementation. Otherwise, it MUST count elements by iterating over the iterator. If the inner iterator is not cloneable, this method SHALL wrap the current object in an
-
See: \IteratorIterator instance and count through that wrapper to avoid performing an invalid clone operation. If the inner iterator is cloneable, this method SHOULD count over a clone so that the original iterator state is preserved as much as possible.
Return Value:
the total number of elements available from the inner iterator