✨ ARCANUM RUNE DIFFICULTY: Archmage Structural

The Flyweight Hex

Sharing common state across multiple pure evaluation contexts.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Transmutation // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
  # The Flyweight Factory (Memoization/Shared state)
  # The common intrinsic state is stored here to prevent duplication.
  sharedCore = {
    system = "x86_64-linux";
    stdenv = "standard-environment-v3";
  };

  # The extrinsic state is combined with the intrinsic flyweight
  createSpell = name: power: {
    inherit name power;
    context = sharedCore;
  };
in
[
  (createSpell "Arcane Missile" 10)
  (createSpell "Frost Nova" 25)
  (createSpell "Blink" 5)
]

The Flyweight pattern in Nix utilizes the inherent structural sharing of the language. Since memory is immutable, sharing sharedCore across thousands of derivations consumes no extra memory during evaluation, optimizing the magical weave.

Runic Tags: #structural #flyweight #nix #sharing