Last active
June 18, 2016 05:03
-
-
Save pcewing/aaab4cc534eb70c2b6b581ab9e99e35e to your computer and use it in GitHub Desktop.
Formatting a function definition with long pattern matching/guard clauses.
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
| # A message is supposed to come in like this but we don't know if the fields are filled out. | |
| message = %{ | |
| route: %{ | |
| destination: "Tim", | |
| source: "Paul" | |
| }, | |
| type: :friend_request, | |
| payload: %{ | |
| size: 32, | |
| content: %{ | |
| message: "I'd like to be your friend." | |
| } | |
| } | |
| } | |
| # Use pattern matching/guard clauses to verify it at least has a target and a message. | |
| def handle_friend_request ( | |
| %{route: %{destination: target}, type: :friend_request, payload: %{content: %{message: message}}} | |
| ) when is_binary(target) and is_binary(message) do | |
| # Write some code here. | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment