The Observer Incantation
Watching the shifting tides of state and reacting in real-time.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Scrying
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CLOJURE PATTERN //
(ns tekromancy.observer)
(def ancient-obelisk (atom {:status :dormant}))
;; Clojure's `add-watch` is the built-in Observer pattern.
(add-watch ancient-obelisk :cultist-watcher
(fn [key ref old-state new-state]
(when (not= (:status old-state) (:status new-state))
(println "The Obelisk shifted to:" (:status new-state)))))
;; Usage:
;; (swap! ancient-obelisk assoc :status :glowing)
Scrying the exact moment an artifact alters its state is critical. The Observer pattern in Clojure is fully integrated into its state management. By affixing an add-watch to an atom, your function is immediately notified whenever the JVM transmutation causes the reference to swap values.
Runic Tags:
#behavioral
#observer
#clojure
#atoms
#watches