⚔️ RPG WARD DIFFICULTY: Apprentice Behavioral

Iterator: The Sequential Seeker

Provide a way to access the elements of an aggregate object sequentially.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RPG PATTERN //
**FREE
Ctl-Opt NoMain;

Dcl-Ds Iterator_t Qualified Template;
  CurrentIndex Int(10);
  MaxCount Int(10);
  DataArray Pointer; 
End-Ds;

Dcl-Proc HasNext Export;
  Dcl-Pi *N Ind;
    pIterator Pointer Value;
  End-Pi;
  Dcl-Ds Iter Likeds(Iterator_t) Based(pIterator);
  Return (Iter.CurrentIndex < Iter.MaxCount);
End-Proc;

Dcl-Proc GetNext Export;
  Dcl-Pi *N Pointer;
    pIterator Pointer Value;
  End-Pi;
  Dcl-Ds Iter Likeds(Iterator_t) Based(pIterator);
  Iter.CurrentIndex += 1;
  // Logic to offset DataArray by CurrentIndex * ElementSize
  Return Iter.DataArray; // Simplified
End-Proc;

Iterator

Whether looping through a flat file or traversing a complex multi-occurrence Data Structure, the Iterator pattern extracts the logic of traversal, freeing the core Business Logic from the mechanics of fetching the next record.

Runic Tags: #behavioral #ibm-i #runes #iterator