⚙️ PURESCRIPT RUNE DIFFICULTY: Apprentice Structural

The Decorator of Web Runes

Dynamically augment the power of web runes via pure functional composition.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Enchantment // Spell Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PURESCRIPT PATTERN //
module Arcane.Decorator where
import Prelude

type Spell = { cast :: String -> String }

baseBolt :: Spell
baseBolt = { cast: \target -> "Magic Bolt strikes " <> target }

-- Decorators are just function composition over the record
withFire :: Spell -> Spell
withFire s = { cast: \target -> s.cast target <> " with burning flames!" }

withShadow :: Spell -> Spell
withShadow s = { cast: \target -> "From the shadows, " <> s.cast target }

ultimateBolt :: Spell
ultimateBolt = withShadow (withFire baseBolt)
Runic Tags: #structural #decorator #purescript #runes