The Builder
Constructing complex magical artifacts via piping spells.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Builder
ARCANUM SCHOOL: Conjuration // Artifact Crafting
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type Potion {
Potion(name: String, mana: Int, healing: Int)
}
pub fn new_potion() -> Potion {
Potion(name: "Nameless Brew", mana: 0, healing: 0)
}
pub fn with_name(potion: Potion, name: String) -> Potion {
Potion(..potion, name: name)
}
pub fn add_mana(potion: Potion, amount: Int) -> Potion {
Potion(..potion, mana: potion.mana + amount)
}
pub fn add_healing(potion: Potion, amount: Int) -> Potion {
Potion(..potion, healing: potion.healing + amount)
}
// Usage:
// new_potion()
// |> with_name("Elixir of the BEAM")
// |> add_mana(50)
// |> add_healing(20)
The Builder
Why use a complex class when you can use the pipe operator (|>) to thread immutable state through pure transformative functions?
Runic Tags:
#conjuration
#builder
#gleam
#pipeline