I am curious when I should be using pattern matching vs guard clauses when defining functions.
For example with pattern matching:
defmodule Exponent do
def power(value, 0), do: 1
def power(value, n), do: value*power(value, n-1)
end
vs guard clause:
defmodule Exponent do
def power(value, n) when n==0, do: 1
def power(value, n), do: value*power(value, n-1)
end
I mean both produce the same result but is one solution preferred over the other? And if so why?
I'm new to Elixir, so the answer to this question is not readily apparent to me (yet). Thanks in advance.