Skip to content

Instantly share code, notes, and snippets.

@curt
Created November 18, 2022 13:37
Show Gist options
  • Save curt/3297bea791b48d4558e36115adfa8ec7 to your computer and use it in GitHub Desktop.
Save curt/3297bea791b48d4558e36115adfa8ec7 to your computer and use it in GitHub Desktop.
Elixir, pattern matching in arguments of named function, simple example
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