💧 ELIXIR ALCHEMY DIFFICULTY: Adept Structural

Decorator

Dynamically augment cyber-constructs with new enchantments without altering their core matrix.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Decorator
ARCANUM SCHOOL: Transmutation // Enhancement
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CONCURRENT ACTOR-MODEL ALCHEMY //
defmodule Tekromancy.Spellcaster do
  def cast(base_damage), do: base_damage
end

defmodule Tekromancy.Decorators do
  def add_fire_damage(fun) do
    fn damage -> fun.(damage) + 50 end
  end

  def add_void_echo(fun) do
    fn damage -> fun.(damage) * 2 end
  end
end

# Usage
# spell = &Tekromancy.Spellcaster.cast/1
# augmented_spell = spell 
#                   |> Tekromancy.Decorators.add_fire_damage()
#                   |> Tekromancy.Decorators.add_void_echo()
# augmented_spell.(100) # => 300

Why permanently mutate a spell when you can wrap it in layers of ephemeral power? By utilizing higher-order functions and closures, the Decorator pattern dynamically chains enchantments. The pipeline of functions enhances the raw telepathic force precisely at runtime, leaving the original incantation untouched.

Runic Tags: #elixir #structural #decorator #higher-order-functions