✨ ARCANUM RUNE DIFFICULTY: Adept Structural

The Decorator

Attach additional responsibilities to a spell dynamically via functional composition.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Enchantment // Augmentation
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
type SpellFunction = Nat -> Nat

baseSpell : SpellFunction
baseSpell n = n * 2

empower : SpellFunction -> SpellFunction
empower spell n = (spell n) + 10

echo : SpellFunction -> SpellFunction
echo spell n = 
  first = spell n
  first + (spell first)
  
-- Applying decorators through function composition
ultimateSpell : SpellFunction
ultimateSpell = empower (echo baseSpell)

In the object-oriented realms, the Decorator requires complex wrapper classes. In Unison’s functional paradigm, decorators are simply higher-order functions or functions that compose over the original spell. By passing a function into a modifier, you weave new enchantments around it, creating a new, uniquely hashed spell that carries the combined properties.

Runic Tags: #structural #decorator #unison #composition