-
-
Notifications
You must be signed in to change notification settings - Fork 0
IterableIterator
github-actions edited this page Mar 31, 2026
·
3 revisions
Class IterableIterator.
A normalized iterator wrapper that ensures any iterable (array or Traversable) is treated as a standard \Iterator.
This utility class simplifies iterator interoperability by converting arrays into \ArrayIterator and wrapping \Traversable instances as needed. It SHALL be used when an \Iterator is expected but the input MAY be any iterable.
Example usage:
$items = new IterableIterator([1, 2, 3]);
foreach ($items as $item) {
echo $item;
}
// Output: 123- Full name:
\FastForward\Iterator\IterableIterator - Parent class:
\FastForward\Iterator\CountableIteratorIterator - This class is marked as final and can't be subclassed
- This class is a Final class
Constructs an IterableIterator from any iterable input.
public __construct(iterable $iterable): mixedArrays are converted to \ArrayIterator; Traversables are passed directly.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$iterable |
iterable | the iterable to wrap as an \Iterator |
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