🌐 REASONML PACT DIFFICULTY: Apprentice Behavioral

Memento in ReasonML

Archiving state snapshots for time manipulation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Reversion
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// REASON PATTERN //
type state = { hp: int, pos: (int, int) };
let save = (s: state) => s; /* Immutable by default! */
let restore = (history, index) => List.nth(history, index);

Due to the unyielding laws of immutability in Reason, the Memento pattern requires zero overhead. You merely store the record in a list to step backwards through time.

Runic Tags: #reason #memento #behavioral