The State of Web Runes
Allow an arcane automaton to alter its behavior when its internal resonance shifts.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: State
ARCANUM SCHOOL: Transmutation // Form Shifting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PURESCRIPT PATTERN //
module Arcane.State where
import Prelude
data FamiliarState = Sleeping | Alert | Attacking
type Familiar = { name :: String, state :: FamiliarState }
poke :: Familiar -> Familiar
poke f@{ state: Sleeping } = f { state = Alert }
poke f@{ state: Alert } = f { state = Attacking }
poke f@{ state: Attacking } = f
describeState :: Familiar -> String
describeState { name, state: Sleeping } = name <> " is dreaming of electric mice."
describeState { name, state: Alert } = name <> " is watching you closely."
describeState { name, state: Attacking } = name <> " casts magic missile!"
Runic Tags:
#behavioral
#state
#purescript
#runes