Extending the Library
Fast Forward Iterators does not require a container, a framework integration, or package-specific service registration. Extension is intentionally simple: build on top of the public iterator base classes and pass around ordinary PHP iterables.
Recommended extension workflow
- accept
iterableas input whenever possible; - normalize it with
IterableIteratorif you need a consistentIterator; - choose the smallest countable base class that matches your design;
- keep the output shape obvious in both naming and documentation.
Choosing the right base class
| Base class | Best for | Example ideas |
|---|---|---|
CountableIteratorAggregate
|
generator-based or delegated iteration | chunking, mapping, flattening, lazy adapters |
CountableIteratorIterator
|
wrappers around an existing iterator | transforming values, remapping keys, peeking helpers |
CountableFilterIterator
|
boolean acceptance rules | path filters, record filters, validation gates |
CountableIterator
|
full stateful control | custom navigation, multi-source coordination, specialized range logic |
Practical advice
- Prefer aggregates when you can express the behavior with
yield. - Prefer wrappers when you want to preserve most behavior of an inner iterator.
- Document whether your iterator preserves original keys or emits normalized sequential keys.
- Call out whether a class buffers values in memory. This matters for
LookaheadIterator, grouping iterators, and generator replay strategies.