Singleton in ReasonML
Module-level global state in a functional world.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
module ManaPool = {
let pool = ref(100);
let drain = amount => {
pool := pool^ - amount;
pool^;
};
};
The Singleton manifests as a module enclosing a ref. It holds the global state of the application’s ley lines.
Runic Tags:
#reason
#singleton
#creational