The Iterator of the Hypertext Labyrinth
Traverse the infinite arrays of lost souls without exposing the underlying data matrix.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Sequencing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// TWINE PATTERN //
:: StoryInit
<<set setup.DataCoreIterator = function(collection) {
return {
index: 0,
items: collection,
hasNext: function() {
return this.index < this.items.length;
},
next: function() {
return this.items[this.index++];
}
};
}>>
:: Passage
<<set $logs to ["Log 1: Anomaly", "Log 2: Breach", "Log 3: Silence"]>>
<<set $iterator to setup.DataCoreIterator($logs)>>
Extracting Data:
<<for _i to 0; $iterator.hasNext(); _i++>>
* <<print $iterator.next()>>
<</for>>
When sweeping through vast, corrupted databanks, hardcoded for loops expose the fragile structure of your collections. The Iterator pattern abstracts the traversal.
The DataCoreIterator holds the internal pointer and provides a clean hasNext() and next() interface. The Weaver steps through the labyrinthine nodes smoothly, ignorant of whether the underlying structure is an array, a linked list, or a procedurally generated nightmare sequence.
Runic Tags:
#behavioral
#iterator
#traversal