Function Arity In Elixir


Arity means how many input parameters Elixir function has. This post is part of the functional language series, and it is based on the remarkable book Elixir In Action by Sasa Juric.

In Elixir, function uniqueness is defined with:

  • Module name
  • Function name
  • Function arity

That takes us to function name overloading. I heard the first time verb overloading in C++.

In Elixir, we can have two functions in the same module with the same name, but with different arity:

In the example above, we have two Salary.Contract.developer functions, with arity 0 Salary.Contract.developer/0 and one with arity one, Salary.Contract.developer/1.

Start IEx and run Salary.Contract.developer Salary.Contract.developer 0.22.

Remember how arity is documented with / because you will read a lot of Elixir documentation.

We use Elixir function arity overloading in practice so we have a function with the largest arity with all the code, and functions with lower arity would call that “largest” function.

In Elixir code, you will also find notation for parameter default values.

Remember, when you use default values using \\ you will create at least two functions with the same function definition. The reason is that we get more functionality with less coding.

When you omit rate parameter in a function call, the rate gets value after \\


  • what is arity
  • how arity is documented
  • how to use function overlading in practice
  • default values

Originally published at on June 5, 2020.

Founder of Tentamen, software testing agency.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store