The Chain of Responsibility
Passing a magical anomaly through sequential defensive wards until one naturally resolves the mathematical discrepancy.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Sequences
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LEAN PATTERN //
namespace MathematicalWards
inductive Anomaly where
| minor
| severe
| critical
def handleMinor : Anomaly → Option String
| Anomaly.minor => some "Minor anomaly resolved by local geometry."
| _ => none
def handleSevere : Anomaly → Option String
| Anomaly.severe => some "Severe anomaly quarantined by higher calculus."
| _ => none
def chain (handlers : List (Anomaly → Option String)) (a : Anomaly) : String :=
match handlers.findSome? (fun h => h a) with
| some res => res
| none => "Catastrophic failure: Anomaly bypassed all wards."
def wardChain := [handleMinor, handleSevere]
#eval chain wardChain Anomaly.severe
end MathematicalWards
Implemented through a list of handler functions returning Option, chained together to lazily evaluate anomalies.
Runic Tags:
#behavioral
#lean4
#chain-of-responsibility
#wards