πŸ’§ ELIXIR ALCHEMY DIFFICULTY: Adept Creational

Singleton

Maintain a singular, omniscient presence within the telepathic network.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Enchantment // Presence
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CONCURRENT ACTOR-MODEL ALCHEMY //
defmodule Tekromancy.OmniMind do
  use GenServer

  # Client API
  def start_link(opts \\ []) do
    GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
  end

  def whisper(thought) do
    GenServer.cast(__MODULE__, {:whisper, thought})
  end

  def scry_thoughts do
    GenServer.call(__MODULE__, :scry)
  end

  # Server Callbacks
  @impl true
  def init(:ok) do
    {:ok, []}
  end

  @impl true
  def handle_cast({:whisper, thought}, state) do
    {:noreply, [thought | state]}
  end

  @impl true
  def handle_call(:scry, _from, state) do
    {:reply, state, state}
  end
end

True Singletons in Elixir are manifestations of singular GenServers registered by name, acting as localized deities within the node. The OmniMind gathers whispers from across the Hive, maintaining a single source of truthβ€”an ever-watchful eye in a sea of parallel actors.

Runic Tags: #elixir #creational #singleton #genserver #omnimind