Skip to content

Commit

Permalink
Add pattern matching ordering note/example (elixirschool#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
brain-geek authored and doomspork committed May 31, 2018
1 parent 04d5501 commit c3a65c9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions en/lessons/basics/functions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
version: 1.0.2
version: 1.1.0
title: Functions
redirect_from:
- /lessons/basics/functions/
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit c3a65c9

Please sign in to comment.