✨ ARCANUM RUNE DIFFICULTY: Apprentice Behavioral

The Command Hex

Encapsulating a request as an attribute set.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Divination // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
  # Receiver
  osHexes = {
    rebuild = config: "Rebuilding OS with ''${config}";
    rollback = "Rolling back to previous generation";
  };

  # Commands (Encapsulating the action and arguments)
  rebuildCommand = config: {
    execute = osHexes.rebuild config;
    name = "RebuildCommand";
  };

  rollbackCommand = {
    execute = osHexes.rollback;
    name = "RollbackCommand";
  };

  # Invoker
  executeCommands = cmds: map (cmd: "Executed: ''${cmd.execute}") cmds;
in
executeCommands [
  (rebuildCommand "flake.nix")
  rollbackCommand
]

The Command pattern encapsulates requests as closures or attribute sets containing an execute mechanism. It isolates the invoker from the receiver, allowing arrays of commands to be queued, logged, or evaluated sequentially within the pure environment.

Runic Tags: #behavioral #command #nix #encapsulation