Created
October 22, 2020 18:00
-
-
Save bacalj/4544fe066c5241618f71f016ce6de900 to your computer and use it in GitHub Desktop.
pattern matching the function input
This file contains hidden or 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 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