The Iterator
Traversing boundless magical dimensions lazily.
β§ GANG OF FOUR LINEAGE & ARCANUM β§
GOF DESIGN PATTERN: Iterator
ARCANUM SCHOOL: Divination // Dimension Traversal
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// OCAML PATTERN //
type 'a seq = Cons of 'a * (unit -> 'a seq) | Nil
let rec infinite_mana n = Cons (n, fun () -> infinite_mana (n + 10))
let rec take n seq =
if n = 0 then []
else match seq with
| Nil -> []
| Cons (x, next) -> x :: take (n - 1) (next ())
let mana_crystals = take 3 (infinite_mana 10)
The Iterator is realized via lazy sequences. We can iterate over boundless magical dimensions without exhausting the material planeβs memory.
Runic Tags:
#Caml Metamagic
#Lazy Sequences
#OCaml