The Iterator Pattern
Traversing a collection of magical artifacts securely.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SWIFT PATTERN //
struct Spellbook: Sequence {
let spells: [String]
func makeIterator() -> IndexingIterator<[String]> {
return spells.makeIterator()
}
}
The Iterator: Scrying the Spellbook
Swift’s Sequence and IteratorProtocol provide native tools for safely traversing the ancient texts of a Spellbook.
Runic Tags:
#swift
#design-pattern
#behavioral