✨ ARCANUM RUNE DIFFICULTY: Apprentice Behavioral

The Iterator: The Pathweaver

Provide a way to sequentially access elements of an aggregate object without exposing its underlying representation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Sequencing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
class_name InventoryIterator extends RefCounted

var _items: Array
var _index: int = 0

func _init(items: Array) -> void:
    _items = items

func has_next() -> bool:
    return _index < _items.size()

func next() -> Variant:
    if has_next():
        var item = _items[_index]
        _index += 1
        return item
    return null

Though modern loops handle much of the burden, a true Iterator object encapsulates the traversal algorithm itself. Whether winding through a linear array or spiraling through a spatial partition tree, the Iterator masks the complexity, yielding artifacts from the void one by one.

Runic Tags: #godot #gdscript #iterator #traversal