⚙️ LEAN RUNE DIFFICULTY: Apprentice Behavioral

The Command

Reifying magical directives into purely functional structures that can be logged, queued, or reversed.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Directives
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// LEAN PATTERN //
namespace MathematicalWards

inductive WardCommand where
  | ignite (power : Nat)
  | extinguish
  | recalibrate (offset : Int)

def executeCommand (state : Nat) (cmd : WardCommand) : Nat :=
  match cmd with
  | WardCommand.ignite p => state + p
  | WardCommand.extinguish => 0
  | WardCommand.recalibrate o => (state : Int) + o |>.toNat

def executeAll (initial : Nat) (cmds : List WardCommand) : Nat :=
  cmds.foldl executeCommand initial

end MathematicalWards

Using an algebraic data type to represent operations as values, allowing them to be stored and executed systematically.

Runic Tags: #behavioral #lean4 #command #wards