✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Prototype Hex

Cloning and mutating base definitions into new magical entities.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Conjuration // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
  # Base prototype
  baseFamiliar = {
    species = "spirit";
    health = 100;
    mana = 50;
    # The cloning mechanism (Nix's `//` update operator)
    clone = self: overrides: self // overrides;
  };

  # Cloning and modifying the prototype
  ravenFamiliar = baseFamiliar.clone baseFamiliar {
    species = "raven";
    flight = true;
    stealth = 80;
  };

  shadowCat = baseFamiliar.clone baseFamiliar {
    species = "cat";
    stealth = 100;
  };
in
[ ravenFamiliar shadowCat ]

In Nix, the Prototype pattern is pervasive. The // operator serves as the ultimate cloner, merging base attribute sets with new overrides. This technique is identical to how derivations are often cloned and modified via override or overrideAttrs.

Runic Tags: #creational #prototype #nix #cloning