Skip to content

techgaun/named_arguments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

named_arguments Hex version Hex downloads Build Status

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.

About

Python like named arguments in Elixir

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages