Popularity
5.1
Stable
Activity
0.0
Stable
49
3
10

Monthly Downloads: 22
Programming language: Elixir
License: Same as Elixir
Tags: Macros    
Latest version: v0.2.1

mdef alternatives and similar packages

Based on the "Macros" category.
Alternatively, view mdef alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of mdef or a related project?

Add another 'Macros' Package

README

MultiDef—Define a function with multiple heads

Add the dependency {:multidef, "> 0.0.0"} to mix.exs.

Use it like this:

defmodule Test do

  import MultiDef

  mdef fib do
    0 -> 0
    1 -> 1
    n -> fib(n-1) + fib(n-1)
  end
end
IO.puts Test.fib(20)

When clauses can be used:

defmodule Test do

  import MultiDef

  mdef fib do
    0 -> 0
    1 -> 1
    n when n > 0 -> fib(n-1) + fib(n-1)
  end
end
IO.puts Test.fib(20)

Does not support default arguments.

Does not enforce that all heads have the same arity (deliberately).


Copyright © 2014 Dave Thomas, The Pragmatic Programmers
@/+pragdave, [email protected]

Licensed under the same terms as Elixir


*Note that all licence references and agreements mentioned in the mdef README section above are relevant to that project's source code only.