From c3a65c9ed6a23560fb3ac49b132249b0e8e78328 Mon Sep 17 00:00:00 2001 From: Oleksandr Rozumii Date: Thu, 31 May 2018 16:41:16 +0300 Subject: [PATCH] Add pattern matching ordering note/example (#1459) --- en/lessons/basics/functions.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/en/lessons/basics/functions.md b/en/lessons/basics/functions.md index 49845ac573..d4a24b62a0 100644 --- a/en/lessons/basics/functions.md +++ b/en/lessons/basics/functions.md @@ -1,5 +1,5 @@ --- -version: 1.0.2 +version: 1.1.0 title: Functions redirect_from: - /lessons/basics/functions/ @@ -37,11 +37,12 @@ As you probably already guessed, in the shorthand version our parameters are ava Pattern matching isn't limited to just variables in Elixir, it can be applied to function signatures as we will see in this section. -Elixir uses pattern matching to identify the first set of parameters which match and invokes the corresponding body: +Elixir uses pattern matching to check through all possible match options and select the first matching option to run: ```elixir iex> handle_result = fn ...> {:ok, result} -> IO.puts "Handling result..." +...> {:ok, _} -> IO.puts "This would be never run as previous will be matched beforehand." ...> {:error} -> IO.puts "An error has occurred!" ...> end