Last active
July 12, 2018 03:11
-
-
Save ktravers/0fa04b42c4d851ea22eab09c4131fd91 to your computer and use it in GitHub Desktop.
Account with custom 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 | |
import Account.Guards, only: [is_private: 2] | |
def display_name(%{first: first, last: last, email: email}) when is_private(first, email) do | |
"<<Redacted>>" | |
end | |
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