Iterator

Implement a standard iterator interface for lists, trees, and graphs.

65|15|Updated Mar 8, 2026
One-click install
npx skills add https://github.com/microwind/ai-skills --skill iterator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Iterator
Source: https://github.com/microwind/ai-skills/tree/main/design-patterns/iterator-pattern
Command: npx skills add https://github.com/microwind/ai-skills --skill iterator

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

Iterator Pattern provides a standardized way to access elements of a collection in sequence without exposing its internal representation.

Core Features & Use Cases

  • External and internal iteration concepts allow flexible traversal strategies.
  • Supports multiple traversal orders (forward, reverse, DFS, BFS) across lists, trees, and graphs.
  • Enables lazy evaluation and the creation of multiple independent iterators for concurrent traversals.
  • Useful in building reusable collection processing pipelines and design-pattern demonstrations.

Quick Start

Create an iterator for your collection and loop through all elements to process them in order.

Frequently Asked Questions about Iterator

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I traverse a collection without exposing its internal structure?

Use the iterator pattern to traverse a collection without exposing its internal representation. It provides a standardized interface with hasNext and next methods, allowing sequential access to elements across lists, trees, and graphs safely.

Can I implement both BFS and DFS traversal orders for trees and graphs?

Yes, you can implement both BFS and DFS traversal orders for trees and graphs. The iterator abstraction supports multiple traversal strategies, including forward, reverse, breadth-first search, and depth-first search, across various complex container structures.

How do I create multiple independent iterators for concurrent traversals?

Create multiple independent iterators by instantiating separate iterator objects from the same collection. This enables concurrent traversals across different orders like forward or DFS, utilizing lazy evaluation to process elements without interference between states.

Does the iterator interface need to handle end-of-collection errors explicitly?

Yes, the iterator interface requires clear error handling for end-of-collection scenarios. The standard hasNext and next methods must safely manage traversal termination, preventing out-of-bounds access when no more elements remain in the sequence.

When should I use an external iterator instead of an internal iteration concept?

Use an external iterator when you need explicit control over the traversal loop, pausing, or applying multiple strategies like BFS and DFS. Internal iteration is better for simple processing pipelines where the collection manages the traversal flow internally.

What is the best way to build reusable collection processing pipelines?

The best way to build reusable collection processing pipelines is applying an iterator design pattern. It decouples traversal logic from data structures through lazy evaluation, allowing multiple independent iterators to process list, tree, or graph elements sequentially.