🎸 GROOVY HEX DIFFICULTY: Apprentice Behavioral

The Iterator Hex

Traversing arcane collections without exposing their internal representations.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Enchantment // Chronomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GROOVY PATTERN //
class SpellBook implements Iterable<String> {
    List<String> spells = ["Fireball", "Haste", "Invisibility"]

    @Override
    Iterator<String> iterator() {
        return spells.iterator()
    }
}

def grimoire = new SpellBook()

// Groovy's native iteration magic
grimoire.each { spell ->
    println "Reading spell: $spell"
}

The Iterator Hex

The Iterator hex abstracts away the looping mechanisms over an aggregate data structure. Groovy bakes this pattern deeply into the Groovy Development Kit (GDK). By simply implementing Iterable, the entire suite of Groovy closure iteration methods (.each, .collect, .find) becomes immediately available, turning complex data traversal into a single line of elegant magic.

Runic Tags: #groovy #behavioral #iterator #gdk