The Composite
Recursive type definitions for hierarchical magic structures.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Transmutation // Sigil Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type Sigil {
Rune(power: Int)
Glyph(parts: List(Sigil))
}
pub fn evaluate_power(sigil: Sigil) -> Int {
case sigil {
Rune(p) -> p
Glyph(parts) -> {
let eval_all = fn(acc, part) { acc + evaluate_power(part) }
gleam/list.fold(parts, 0, eval_all)
}
}
}
The Composite
Algebraic data types naturally represent the Composite pattern. A Sigil is either a single Rune or a Glyph composed of multiple Sigils.
Runic Tags:
#transmutation
#composite
#gleam