The Command
Encapsulating spell invocations as first-class data.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Evocation // Spell Storing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type SpellCommand {
CastFireball(mana: Int)
CastHeal(target: String)
}
pub fn invoke(command: SpellCommand) -> String {
case command {
CastFireball(m) -> "Dealt " <> gleam/int.to_string(m * 2) <> " damage!"
CastHeal(t) -> "Healed " <> t <> "!"
}
}
pub fn invoke_all(commands: List(SpellCommand)) -> List(String) {
gleam/list.map(commands, invoke)
}
The Command
Data types represent our commands. We can store, map, filter, and fold over them before passing them to the interpreter function.
Runic Tags:
#evocation
#command
#gleam