-
-
Notifications
You must be signed in to change notification settings - Fork 0
ChainIterableIterator
An iterator that chains multiple iterable sources together into a single unified iterator.
This iterator SHALL accept any number of iterable values (arrays, Traversables, or Iterators) and iterate over them in order. When the current iterator is exhausted, it proceeds to the next.
The class MUST ensure all incoming values are wrapped as \Iterator instances, either natively or by converting Traversables or arrays using standard SPL iterators.
Example usage:
$it = new ChainIterableIterator([1, 2], new ArrayIterator([3, 4]));
foreach ($it as $value) {
echo $value;
}
// Output: 1234- Full name:
\FastForward\Iterator\ChainIterableIterator - This class is marked as final and can't be subclassed
- This class implements:
Iterator,Countable - This class is a Final class
Constructs a ChainIterableIterator with one or more iterable sources.
public __construct(iterable $iterables): mixedEach iterable SHALL be normalized to a \Iterator instance using:
- \ArrayIterator for arrays
- \IteratorIterator for Traversable objects
- Directly used if already an \Iterator
Parameters:
| Parameter | Type | Description |
|---|---|---|
$iterables |
iterable | One or more iterable data sources to chain. |
Counts the total number of elements across all chained iterators.
public count(): intThis method iterates through each underlying iterator and sums their counts.
Return Value:
the total count of elements in all chained iterators
Rewinds all underlying iterators and resets the position.
public rewind(): voidEach chained iterator SHALL be rewound to its beginning.
Checks whether the current position is valid across chained iterators.
public valid(): boolIteration continues until the current iterator is valid or all are exhausted.
Return Value:
TRUE if there are more elements to iterate; FALSE otherwise
Returns the current element from the active iterator.
public current(): mixed|nullReturn Value:
the current element or NULL if iteration is invalid
public key(): int|nullMoves the pointer of the active iterator forward.
public next(): void