Skip to content

Instantly share code, notes, and snippets.

@bradleyd
Last active August 29, 2015 14:05
Show Gist options
  • Save bradleyd/e4254c0e647dc7bb8371 to your computer and use it in GitHub Desktop.
Save bradleyd/e4254c0e647dc7bb8371 to your computer and use it in GitHub Desktop.
Pattern matching on many parameters
defmodule Message do
defstruct to: nil, subject: nil, text: nil, html: nil, from: nil, bcc: nil
# this is the minimum needed to send an email
def new(%{to: to, subject: subject, text: text, from: from}) do
{:ok, %Message{to: to, subject: subject, text: text, from: from} }
end
def new(%{to: to, subject: subject, html: html, from: from}) do
{:ok, %Message{to: to, subject: subject, html: html, from: from} }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment