Chain of Responsibility
Pass telepathic decrees through a lineage of guardians until one handles it.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Enchantment // Command-Routing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CONCURRENT ACTOR-MODEL ALCHEMY //
defmodule Tekromancy.RequestHandler do
def handle_request(request, [handler | rest]) do
case handler.(request) do
{:handled, result} -> result
:pass -> handle_request(request, rest)
end
end
def handle_request(_request, []), do: "Request lost in the void."
end
# Usage
# handlers = [
# fn req -> if req == :low, do: {:handled, "Acolyte handled it"}, else: :pass end,
# fn req -> if req == :high, do: {:handled, "Archmage handled it"}, else: :pass end
# ]
# Tekromancy.RequestHandler.handle_request(:high, handlers)
A whisper enters the telepathic network. Is it a mundane chore or a catastrophic breach? The Chain of Responsibility routes the command through a list of function handlers, each deciding whether to act or pass the burden up the hierarchy. Pattern matching makes evaluating these decisions elegantly precise.
Runic Tags:
#elixir
#behavioral
#chain-of-responsibility
#routing