Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pragdave/mdef
Easily define multiple function heads in elixir
https://github.com/pragdave/mdef
Last synced: 7 days ago
JSON representation
Easily define multiple function heads in elixir
- Host: GitHub
- URL: https://github.com/pragdave/mdef
- Owner: pragdave
- Created: 2014-07-12T21:15:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-08T01:19:28.000Z (over 4 years ago)
- Last Synced: 2024-10-02T06:29:07.595Z (about 1 month ago)
- Language: Elixir
- Size: 7.81 KB
- Stars: 49
- Watchers: 3
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - Easily define multiple function heads in Elixir. (Macros)
- fucking-awesome-elixir - mdef - Easily define multiple function heads in Elixir. (Macros)
- awesome-elixir - mdef - Easily define multiple function heads in Elixir. (Macros)
README
MultiDef—Define a function with multiple heads
==============================================Add the dependency `{:multidef, "> 0.0.0"}` to mix.exs.
Use it like this:
```elixir
defmodule Test doimport MultiDef
mdef fib do
0 -> 0
1 -> 1
n -> fib(n-1) + fib(n-1)
end
end
``````elixir
IO.puts Test.fib(20)
```When clauses can be used:
```elixir
defmodule Test doimport MultiDef
mdef fib do
0 -> 0
1 -> 1
n when n > 0 -> fib(n-1) + fib(n-1)
end
end
``````elixir
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