-
-
Notifications
You must be signed in to change notification settings - Fork 0
InterleaveIteratorIterator
Class InterleaveIteratorIterator.
Interleaves elements from multiple iterators in a round-robin fashion.
This iterator alternates between multiple traversable sources, returning one element from each before cycling back to the first. The iteration stops once all iterators are exhausted.
- Full name:
\FastForward\Iterator\InterleaveIteratorIterator - Parent class:
\FastForward\Iterator\CountableIterator
Initializes the InterleaveIteratorIterator.
public __construct(iterable $iterators): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$iterators |
iterable | The iterators to be interleaved. |
Throws:
if no iterators are provided
Retrieves the current element from the active iterator.
public current(): mixedReturn Value:
the current element
Retrieves the current key from the active iterator or a normalized sequential key.
public key(): string|intIf the active iterator's current key is a string, it is returned directly. Otherwise, a normalized sequential numeric key is returned based on the position of yielded values without string keys.
Return Value:
the current key
public next(): voidChecks if at least one iterator still has elements.
public valid(): boolReturn Value:
true if there are remaining elements, false otherwise
public rewind(): voidCounts 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