Mahaul - Supercharge the environment variables usage in your Elixir app

Can you give some brief example of how such a dynamic pattern matching can work at compile time? Form what I can think of, the following will give you runtime errors without any compile time warnings.

defmodule Env do
  def get_env("VAR_1"), do: "..."
  def get_env("VAR_2"), do: "..."
end

defmodule SomeModule do
  def something() do
    Env.get_env("VAR_1") # works
    Env.get_env("VAR_2") # works
    Env.get_env("VAR_3") # runtime error with no compile time warnings
  end
end

vs

defmodule Env do
  use Mahaul,
    VAR_1: [type: :str],
    VAR_2: [type: :num]
end

defmodule SomeModule do
  def something() do
    Env.var_1() # works
    Env.var_2() # works
    Env.var_3() # compile time warnings for non-existing method call
  end
end

:heavy_heart_exclamation: :heavy_heart_exclamation: :heavy_heart_exclamation:

2 Likes