⚡ ZIG ALCHEMY DIFFICULTY: Adept Behavioral

The Iterator: Leyline Traversal

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

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Dowsing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// BLAZING-FAST ZIG ALCHEMY //
const std = @import("std");

pub const Node = struct { value: u32, next: ?*Node };

pub const LeylineIterator = struct {
    current: ?*Node,

    pub fn next(self: *LeylineIterator) ?u32 {
        if (self.current) |node| {
            self.current = node.next;
            return node.value;
        }
        return null;
    }
};

Navigating the jagged shards of memory requires a steady hand. Leyline Traversal encapsulates the iteration logic, giving the technomage a clean stream of values. You never need to know if the leylines are a linked list, an array, or a dimensional rift—just call next().

Runic Tags: #iterator #behavioral #zig #traversal