The Decorator Incantation
Dynamically layering new enchantments upon an existing spell.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Enchantment // Layering
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CLOJURE PATTERN //
(ns tekromancy.decorator)
;; Higher-order functions act as natural decorators in Clojure.
(defn base-spell [target]
(str "Striking " target " with pure energy"))
(defn with-fire [spell-fn]
(fn [target]
(str (spell-fn target) " and searing flames")))
(defn with-echo [spell-fn]
(fn [target]
(str (spell-fn target) "... (echo)")))
;; Usage:
;; (def ultimate-spell (-> base-spell with-fire with-echo))
;; (ultimate-spell "the beast")
To augment a spell with fire and echoes, one need not forge an entirely new artifact. By wrapping functions within higher-order functions, the Decorator pattern dynamically layers mutable enchantments atop immutable behavior, chaining functional glyphs seamlessly.
Runic Tags:
#structural
#decorator
#clojure
#higher-order-functions