☎️ ERLANG HIVE DIFFICULTY: Adept Structural

The Flyweight of the Hive Switchboard

Sharing immutable state via ETS tables.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Flyweight
ARCANUM SCHOOL: Enchantment // Binding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// ERLANG PATTERN //
-module(the_flyweight).
-export([init/0, get_shared_lore/1]).

init() ->
    ets:new(lore_table, [named_table, public, read_concurrency]).

get_shared_lore(Key) ->
    case ets:lookup(lore_table, Key) of
        [{Key, Value}] -> Value;
        [] -> undefined
    end.

The Flyweight

When thousands of spirits need the exact same memory, we engrave it into the ETS crystalline lattice.

Runic Tags: #erlang #actors #telepathy #switchboard #flyweight