-
-
Notifications
You must be signed in to change notification settings - Fork 0
GeneratorRewindableIterator
Class GeneratorRewindableIterator.
An iterator that allows rewinding over a generator by caching its values.
This class wraps a generator or a closure returning a generator, enabling multiple iterations over the generated sequence by caching its results.
- Full name:
\FastForward\Iterator\GeneratorRewindableIterator - Parent class:
\FastForward\Iterator\CountableIterator
Initializes the GeneratorRewindableIterator with a generator or a closure returning a generator.
public __construct(\Closure|\Generator $generator): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$generator |
\Closure|\Generator | a generator instance or a callable that returns a generator |
Rewinds the iterator to the beginning.
public rewind(): voidThis method creates a new IteratorIterator instance wrapping the
GeneratorCachingIteratorAggregate, ensuring that the generator can be reused.
Retrieves the current element from the iterator.
public current(): mixedReturn Value:
the current element
Retrieves the key of the current element.
public key(): mixedReturn Value:
the key associated with the current element
Advances the iterator to the next element.
public next(): voidChecks if the current iterator position is valid.
public valid(): boolReturn Value:
true if the current position is valid, false otherwise
Counts the number of elements in the iterable.
public count(): intIf 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