pattern-iterator

Implement iterator and collection classes with hasNext/next interfaces for sequential traversal.

Updated Mar 26, 2026
One-click install
npx skills add https://github.com/johnnystefan/test-saas-business --skill pattern-iterator
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pattern-iterator
Source: https://github.com/johnnystefan/test-saas-business/tree/main/skills/design-patterns/behaviorals/pattern-iterator
Command: npx skills add https://github.com/johnnystefan/test-saas-business --skill pattern-iterator

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill keeps traversal logic outside business aggregates by teaching how to sequentially access collection elements without exposing their internal representations, preventing clients from corrupting sensitive domain structures.

Core Features & Use Cases

  • Iterator and Collection Interfaces: Define the shared next()/hasNext() contract plus a method for creating iterators, establishing a uniform traversal API.
  • Concrete Iterator Implementation: Encapsulate traversal state for specific domain collections, enabling deterministic pagination, filtering, or lazy loading behaviors.
  • Use Case: When a club aggregate exposes a roster, apply this pattern to iterate through player entities safely for reporting or batch invitations.

Quick Start

Ask the skill to generate an iterator implementation for your domain collection that keeps the aggregate root’s internal list private while exposing ordered access.

Frequently Asked Questions about pattern-iterator

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

FAQPage Schema
How do I iterate through a TypeScript collection without exposing its internal array?

To iterate through a TypeScript collection without exposing internal arrays, implement the Iterator pattern by defining concrete iterator and collection classes that maintain traversal state and expose hasNext and next interfaces for sequential access.

What is the Iterator design pattern used for in domain-driven design?

The Iterator design pattern in domain-driven design is used to sequentially access aggregate collection elements while keeping the internal data structures private, preventing clients from corrupting sensitive domain structures during traversal.

How do I implement a custom iterator for controlled collection traversal in TypeScript?

Implement a custom iterator by defining shared next and hasNext contract interfaces, then building concrete iterator classes that encapsulate traversal state for your specific domain collections to enable deterministic pagination or lazy loading.

When should I use a custom iterator instead of standard array methods for domain collections?

Use a custom iterator when implementing aggregation or domain-driven collections that require controlled traversal logic, deterministic pagination, or filtering behaviors that standard array methods cannot safely provide without exposing internal structures.

Can I apply the Iterator pattern to filter or lazily load collection elements?

Yes, the Iterator pattern supports filtering and lazy loading behaviors by encapsulating traversal state within concrete iterator implementations, allowing domain collections to fetch or process elements sequentially on demand.