⚙️ LEAN RUNE DIFFICULTY: Adept Behavioral

The Observer

Subscribing auxiliary wards to the fluctuations of a primary core, reacting instantly to any mathematical variance.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Observer
ARCANUM SCHOOL: Divination // Reaction
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LEAN PATTERN //
namespace MathematicalWards

structure Subject (State : Type) where
  state : State
  observers : List (State → State)

def notify (sub : Subject Nat) : Subject Nat :=
  let newState := sub.observers.foldl (fun s obs => obs s) sub.state
  { sub with state := newState }

def addObserver (sub : Subject Nat) (obs : Nat → Nat) : Subject Nat :=
  { sub with observers := obs :: sub.observers }

end MathematicalWards

The Observer pattern expressed functionally: observers are purely functional state transformers applied in sequence over the subject’s state.

Runic Tags: #behavioral #lean4 #observer #wards