gof-iterator
Installation
SKILL.md
One-line summary
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
When to use this skill
- Multiple aggregate types must be traversed uniformly even though they use different internal structures (one uses an array, another a hash map, a third a linked list).
- A method consumes a collection but should not depend on which concrete collection type it is.
- Implementing a custom collection that needs to be traversable in client code (a tree, a graph, a paginated remote dataset).
When NOT to use this skill
- The language already gives you iteration over standard collections (every modern language does) and you're not designing a custom collection — just use the language's
for-each/ iteration. - The "iteration" is really a transform or filter pipeline — that's a higher-level concept; reach for the language's streams / sequences.
- You need random access, not sequential access — Iterator is sequential by definition.
Core content
The pattern separates two concerns: