Skip to content

Instantly share code, notes, and snippets.

@shahryarjb
Created April 21, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahryarjb/cc7244e0e7063ab2597163232464e518 to your computer and use it in GitHub Desktop.
Save shahryarjb/cc7244e0e7063ab2597163232464e518 to your computer and use it in GitHub Desktop.
# my blog : https://trangell.com/fa/
# public : http://iranonrails.ir
defmodule Guard do
def what_is(x) when is_number(x) do
IO.puts "#{x} is a number"
end
def what_is(x) when is_list(x) do
IO.puts "#{inspect(x)} is a list"
end
def what_is(x) when is_atom(x) do
IO.puts "#{x} is an atom"
end
end
Guard.what_is(99) # => 99 is a number
Guard.what_is(:cat) # => cat is an atom
Guard.what_is([1,2,3]) # => [1,2,3] is a list
# defmodule Factorial do
# def of(0), do: 1
# def of(n) when n > 0 do
# n * of(n-1)
# end
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment