Created
November 18, 2022 13:37
-
-
Save curt/3297bea791b48d4558e36115adfa8ec7 to your computer and use it in GitHub Desktop.
Elixir, pattern matching in arguments of named function, simple example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Results do | |
def strange_results(%{a: 0} = params) do | |
%{params | a: 1000} | |
end | |
def strange_results(params) do | |
params | |
end | |
end | |
# iex(1)> Results.strange_results(5) | |
# 5 | |
# iex(2)> Results.strange_results(%{a: 4, b: 5}) | |
# %{a: 4, b: 5} | |
# iex(3)> Results.strange_results(%{a: 0, b: 5}) | |
# %{a: 1000, b: 5} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment