The Command of Jsonnet
Encapsulating operations as objects.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Delayed Execution
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local AddUserCmd(user) = { action: "ADD", payload: user };
local DelUserCmd(user) = { action: "DEL", payload: user };
local CommandExecutor(state, cmds) =
std.foldl(
function(st, cmd)
if cmd.action == "ADD" then st + [cmd.payload]
else if cmd.action == "DEL" then std.filter(function(x) x != cmd.payload, st)
else st,
cmds,
state
);
{
finalState: CommandExecutor(["alice"], [AddUserCmd("bob"), DelUserCmd("alice")])
}
Commands are encoded as declarative objects, stored and eventually executed by an interpreter function, enabling deferred manipulation of the data state.
Runic Tags:
#behavioral
#command
#jsonnet