If a function has multiple sentences, Elixir will execute each sentence until it finds one that matches. This allows you to "filter" based on the arguments provided - especially useful if functions do not have common logic.
def load([]), do: IO.puts("empty") def load(token) when token == nil, do: IO.puts("nil")
The second paragraph illustrates the use of guards that allow more general matches, the number of predicates that are valid as guards , all of which can be attached to (almost) any expression that is used to switch functional arguments, recursively or otherwise.
This agreement applies to all existing BEAM languages ββand is useful to keep in mind when reading the OTP documentation.
source share