The Chain of Wards
Passing magical anomalies through a sequence of protective layers until handled.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
interface WardChain
exposes [Anomaly, processAnomaly, fireWard, iceWard, voidWard]
imports []
Anomaly : { type : [Fire, Ice, Void], intensity : U64 }
Handler : (Anomaly -> Result Str Anomaly)
fireWard : Handler
fireWard = \anomaly ->
if anomaly.type == Fire then
Ok "Fire anomaly absorbed by Fire Ward."
else
Err anomaly
iceWard : Handler
iceWard = \anomaly ->
if anomaly.type == Ice then
Ok "Ice anomaly absorbed by Ice Ward."
else
Err anomaly
voidWard : Handler
voidWard = \anomaly ->
if anomaly.type == Void then
Ok "Void anomaly banished by Void Ward."
else
Err anomaly
# The Chain
processAnomaly : Anomaly -> Str
processAnomaly = \anomaly ->
handlers = [fireWard, iceWard, voidWard]
result = List.walkUntil handlers (Err anomaly) \_, handler ->
when handler anomaly is
Ok msg -> Break (Ok msg)
Err a -> Continue (Err a)
when result is
Ok msg -> msg
Err _ -> "Anomaly breached all wards!"
Runic Tags:
#fast-functional-wards
#roc
#chain-of-responsibility