Elixir Function Pattern Matching

[Solved] Elixir Function Pattern Matching | Elixir - Code Explorer | yomemimo.com
Question : elixir function pattern matching

Answered by : nguyen-quang-huy

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
iex> handle_result.({:ok, some_result}) # Handling result...
iex> handle_result.({:error}) # An error has occurred!

Source : | Last Update : Tue, 07 Jun 22

Answers related to elixir function pattern matching

Code Explorer Popular Question For Elixir