The Command
Encapsulating a spell execution as a monolithic data structure, allowing deferred or queued Gallina invocations.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
(* Gallina Ward: Command *)
Require Import String List.
Import ListNotations.
(* The Receiver *)
Record Crystal := {
charge : nat
}.
(* Commands are encapsulated state transformations *)
Definition Command := Crystal -> Crystal.
Definition overchargeCmd : Command := fun c => {| charge := c.(charge) + 100 |}.
Definition drainCmd : Command := fun c => {| charge := 0 |}.
(* The Invoker processes a queue of commands *)
Fixpoint executeQueue (queue : list Command) (target : Crystal) : Crystal :=
match queue with
| [] => target
| cmd :: rest => executeQueue rest (cmd target)
end.
Definition initCrystal := {| charge := 50 |}.
Definition ritualQueue := [overchargeCmd; overchargeCmd; drainCmd; overchargeCmd].
Definition finalCrystal := executeQueue ritualQueue initCrystal.
Runic Tags:
#command
#gallina
#wards