λ HASKELL SIGILS DIFFICULTY: Adept Behavioral

The Chain of Responsibility

Monadic failure and the Maybe monad to pass the burden along the chain.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Divination // Flow
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// PURE FUNCTIONAL VOID SIGIL //
module ChainOfResponsibility where
import Control.Applicative ((<|>))
handler1 x = if x == 1 then Just "H1 handled" else Nothing
handler2 x = if x == 2 then Just "H2 handled" else Nothing
chain x = handler1 x <|> handler2 x
Runic Tags: #chain #maybe-monad #behavioral