Skip to content

Instantly share code, notes, and snippets.

@bacalj
Created October 22, 2020 18:00
Show Gist options
  • Save bacalj/4544fe066c5241618f71f016ce6de900 to your computer and use it in GitHub Desktop.
Save bacalj/4544fe066c5241618f71f016ce6de900 to your computer and use it in GitHub Desktop.
pattern matching the function input
defmodule Food do
def test_food(%{ name: "raisins"} = food) do
"The food is tiny, gross #{food.name}. It tastes #{food.taste}."
end
def test_food(food) do
"The food is #{food.name}. It tastes #{food.taste}."
end
end
raisins = %{ name: "raisins", taste: "bad" }
pizza = %{ name: "Pizza", taste: "good"}
Food.test_food(pizza) |> IO.puts
Food.test_food(raisins) |> IO.puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment