The Visitor
Dispatching operations on sum types via pattern matching.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Essence Extraction
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type Entity {
Demon(power: Int)
Fae(trickery: Int)
}
pub fn calculate_threat(entity: Entity) -> Int {
case entity {
Demon(power) -> power * 10
Fae(trickery) -> trickery * 5
}
}
The Visitor
In functional languages, the Visitor pattern is just pattern matching over a sum type. No double dispatch required.
Runic Tags:
#divination
#visitor
#gleam