✨ ARCANUM RUNE DIFFICULTY: Apprentice Structural

The Composite

Compose magical artifacts into tree structures to represent part-whole hierarchies.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Conjuration // Constructs
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
structural type Construct = 
  Rune Text |
  Sigil [Construct]
  
powerLevel : Construct -> Nat
powerLevel c = match c with
  Rune t -> Text.size t
  Sigil cs -> List.foldLeft (acc sub -> acc + powerLevel sub) 0 cs

The Composite pattern naturally maps to Unison’s recursive algebraic data types. A Construct can be a single Rune (a leaf node) or a Sigil containing multiple sub-constructs. Operations upon the construct, like calculating its inherent power, are evaluated through simple, pure recursion, traversing the content-addressed tree flawlessly.

Runic Tags: #structural #composite #unison #recursion