-
-
Notifications
You must be signed in to change notification settings - Fork 0
GeneratorCachingIteratorAggregate
A caching iterator aggregate designed to wrap a generator and cache its results.
This class allows wrapping a Generator or a callable returning a generator,
caching its values to enable multiple iterations over the same dataset.
- Full name:
\FastForward\Iterator\GeneratorCachingIteratorAggregate - Parent class:
\FastForward\Iterator\CountableIteratorAggregate
Initializes the caching iterator with a generator or a callable returning a generator.
public __construct(callable|\Generator $generator): mixedIf a callable is provided, it is wrapped in a ClosureFactoryIteratorAggregate to generate the iterator.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$generator |
callable|\Generator | the generator or a callable returning a generator |
Retrieves the iterator, either from the cache or the generator itself.
public getIterator(): \TraversableThis method ensures that once a generator is iterated, its values remain available for subsequent iterations.
Return Value:
the cached or fresh iterator
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