πŸ”΄ SCALA ALCHEMY DIFFICULTY: Adept Structural

The Composite Gestalt

Treat individual spells and sprawling ritual arrays uniformly as a single magical tree.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Composite
ARCANUM SCHOOL: Illusion // Gestalt
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCALA PATTERN //
sealed trait SpellComponent {
  def manaCost: Int
}

case class SimpleSpell(cost: Int) extends SpellComponent {
  override def manaCost: Int = cost
}

case class SpellArray(components: List[SpellComponent]) extends SpellComponent {
  override def manaCost: Int = components.map(_.manaCost).sum
}

// Usage:
// val array = SpellArray(List(SimpleSpell(10), SpellArray(List(SimpleSpell(5), SimpleSpell(15)))))
// println(array.manaCost) // 30

Trees of pure functional magic. The Composite pattern elegantly models recursive magical structures using Scala’s sealed traits and case classes.

Runic Tags: #scala #structural #fractal-magic