The Chain of Responsibility
Sequencing protective wards via function chaining.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Sequential Wards
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type Request {
Request(payload: String)
}
pub type Handler = fn(Request) -> Result(Request, String)
pub fn check_auth(req: Request) -> Result(Request, String) {
// Auth logic
Ok(req)
}
pub fn check_mana(req: Request) -> Result(Request, String) {
// Mana logic
Ok(req)
}
pub fn handle_request(req: Request) -> Result(Request, String) {
use req <- gleam/result.try(check_auth(req))
use req <- gleam/result.try(check_mana(req))
Ok(req)
}
The Chain of Responsibility
By combining Result types and use expressions, we chain handlers where a failure in any ward halts the entire sequence.
Runic Tags:
#abjuration
#chain-of-responsibility
#gleam