Named arguments in Elixir
This package abuses macros to use keyword lists and maps to mimic named arguments in Elixir.
Installation:
{:named_arguments, "~> 0.1.0"}
The usage is very simple:
defmodule Analyzer do
use NamedArguments
def query(opts \\ [aggregate: :sum, range: "1h"]) do
IO.puts "running query with #{opts[:aggregate]} over range #{opts[:range]}"
end
end
Analyzer.query()
# running query with sum over range 1h
Analyzer.query(aggregate: :avg)
# running query with avg over range 1h
While the above example shows Keyword list example, this works fine with maps as well.
You can check the test for more examples.