✨ GLEAM ALCHEMY DIFFICULTY: Adept Behavioral

The Mediator

Coordinating actors through a central hub.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Mediator
ARCANUM SCHOOL: Divination // Ley Line Nexus
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
import gleam/erlang/process.{type Subject}
import gleam/otp/actor

pub type NexusMsg {
  Broadcast(String)
}

fn handle_nexus(msg: NexusMsg, nodes: List(Subject(String))) -> actor.Next(NexusMsg, List(Subject(String))) {
  case msg {
    Broadcast(spell) -> {
      gleam/list.each(nodes, fn(node) { process.send(node, spell) })
      actor.continue(nodes)
    }
  }
}

The Mediator

A dedicated actor serves as a nexus, broadcasting messages to subscribed nodes without them needing direct references to one another.

Runic Tags: #divination #mediator #gleam #otp