RepeatableIteratorIterator
An iterator that enables repeated iteration over a finite subset of an infinite iterator.
Description
This iterator wraps an Iterator and applies a LimitIterator over an InfiniteIterator,
allowing a limited number of repeated iterations without modifying the underlying iterator.
It also implements Countable to return the number of elements available in the limited iteration.
Usage Example:
Description
Limiting an Infinite Iterator
use FastForward\Iterator\RepeatableIteratorIterator;
use ArrayIterator;
$data = new ArrayIterator([1, 2, 3, 4, 5]);
$repeatableIterator = new RepeatableIteratorIterator($data, 3);
echo count($repeatableIterator); // Outputs: 3
foreach ($repeatableIterator as $value) {
echo $value . ' '; // Outputs: 1 2 3
}
Note: The iterator does not consume values permanently,
as it is backed by an InfiniteIterator and LimitIterator.
Interfaces
Properties
Methods
Initializes the RepeatableIteratorIterator.
Returns the number of elements that can be iterated per cycle.
Initializes the RepeatableIteratorIterator.
public
__construct(
iterable<string|int, mixed>
$iterator,
int
$limit[,
int
$offset = 0]) : mixed
Parameters
$iterator
:
iterable<string|int, mixed>
Description
the iterator to be wrapped in an infinite loop
$limit
:
int
Description
the maximum number of elements to iterate over per cycle
$offset
:
int
=
0
Description
the starting offset within the iterator
Returns the number of elements that can be iterated per cycle.
public
count() : int
Return values
Description
the count of items in the limited iteration