Skip to content

Instantly share code, notes, and snippets.

@blackode
Last active March 8, 2017 08:34
Show Gist options
  • Save blackode/b0c1d4ead9d42c59231b84aa61bcad65 to your computer and use it in GitHub Desktop.
Save blackode/b0c1d4ead9d42c59231b84aa61bcad65 to your computer and use it in GitHub Desktop.
when conditions as functions
defmodule Hello do
def hello(name,age) when is_kid(age) do
IO.puts "Hello Kid #{name}"
end
def hello(name,age) when is_adult(age) do
IO.puts "Hello Mister #{name}"
end
def is_kid age do
age < 12
end
def is_adult age do
age > 18
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment