New to Elixir, trying to understand what this syntax means:
MyApplication.Module.function/2
What does the number after the function represent?
In Elixir and Erlang functions can have multiple body clauses (in contrast to C++, Java etc.), so to distinguish we use arity, where it's simply number of arguments.
For example:
defmodule Math do
def sum(x) do
x + 0
end
def sum(x, y) do
x + y
end
end
So in this you have two similar yet different functions: sum/1
and sum/2
.
Quite often you can see that the function with larger number of arguments is used internally to calculcate the result.