Skip to content

Instantly share code, notes, and snippets.

@ktravers
Last active July 12, 2018 03:11
Show Gist options
  • Save ktravers/0fa04b42c4d851ea22eab09c4131fd91 to your computer and use it in GitHub Desktop.
Save ktravers/0fa04b42c4d851ea22eab09c4131fd91 to your computer and use it in GitHub Desktop.
Account with custom guard clauses
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