patternsiterator

Iterator Pattern pattern for C development

⭐1stars🔀0forks📁View on GitHub🕐Updated Jan 4, 2026

When & Why to Use This Skill

This Claude skill provides a standardized implementation of the Iterator Pattern specifically tailored for C development. It enables developers to provide sequential access to collection elements without exposing the underlying data structures, promoting better encapsulation, modularity, and cleaner code architecture in systems-level programming.

Use Cases

  • Scrollback Traversal: Iterating through visible lines for rendering in terminal applications or UI components without exposing internal ring buffer mechanics.
  • Message Iteration: Walking through session message histories to efficiently build context windows for Large Language Model (LLM) processing.
  • Data Structure Abstraction: Providing a unified interface for traversing complex custom collections like linked lists, trees, or buffers where hiding implementation details is critical for maintainability.
namepatterns/iterator
descriptionIterator Pattern pattern for C development

Iterator Pattern

Provide sequential access to collection elements without exposing underlying structure. In C, typically a struct with next() function or index-based traversal.

ikigai Application

Scrollback traversal: Iterate visible lines for rendering without exposing ring buffer internals.

Message iteration: Walk session messages for LLM context building.

Implementation options:

// Index-based (simple)
for (size_t i = 0; i < scrollback->count; i++) { ... }

// Iterator struct (encapsulated)
ik_iter_t *iter = ik_scrollback_iter(scrollback);
while (ik_iter_next(iter, &line)) { ... }

Current approach: Index-based iteration is sufficient. Iterator struct adds value when traversal logic is complex or needs to hide internals.