Created
July 12, 2018 03:06
-
-
Save ktravers/a9dbeae69c7db8acb3778b5fbd06a4de to your computer and use it in GitHub Desktop.
Guard clauses
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 Account do | |
def display_name(%{first: first, last: last}) when not is_nil(first) do | |
String.trim("#{first} #{last}") | |
end | |
def display_name(%{username: username}) when not is_nil(username) do | |
"#{username}" | |
end | |
def display_name(_), do: "New User" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment