The Strategy Hex
Injecting algorithmic variations into derivation contexts.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Strategy
ARCANUM SCHOOL: Divination // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
# Strategies
fetchFromGitHub = repo: "Fetching ''${repo} from GitHub using API...";
fetchFromGitLab = repo: "Fetching ''${repo} from GitLab using tarball...";
fetchFromLocal = repo: "Copying ''${repo} from local filesystem...";
# Context
fetchGrimoire = strategy: repo:
strategy repo;
in
{
gh = fetchGrimoire fetchFromGitHub "arcane-repo";
gl = fetchGrimoire fetchFromGitLab "arcane-repo";
}
The Strategy pattern defines a family of algorithms, encapsulating each one. In Nixpkgs, functions like fetchurl, fetchgit, and fetchFromGitHub are distinct strategies that can be passed dynamically into package definitions to resolve sources.
Runic Tags:
#behavioral
#strategy
#nix
#fetchers