Skip to content

Instantly share code, notes, and snippets.

@javiervidal
Last active March 31, 2017 12:31
Show Gist options
  • Save javiervidal/a3dd5a23e3b9ac70d80d7271a7eddfb8 to your computer and use it in GitHub Desktop.
Save javiervidal/a3dd5a23e3b9ac70d80d7271a7eddfb8 to your computer and use it in GitHub Desktop.
Modules and Named Functions
defmodule Factorial do
def of(0), do: 1
def of(n), do: n * of(n-1)
end
defmodule Factorial do
def of(0), do: 1
def of(n) when n > 0 do
n * of(n-1)
end
end
defmodule Chop do
def guess(actual, low..high) do
currently_guessed = div(low+high, 2)
IO.puts "Is it #{currently_guessed}"
try(actual, currently_guessed, low..high)
end
defp try(actual, currently_guessed, _) when actual == currently_guessed do
IO.puts(currently_guessed)
end
defp try(actual, currently_guessed, _low..high) when actual > currently_guessed do
guess(actual, currently_guessed+1..high)
end
defp try(actual, currently_guessed, low.._high) when actual < currently_guessed do
guess(actual, low..currently_guessed-1)
end
end
people = DB.find_customers orders = Orders.for_customers(people) tax = sales_tax(orders, 2016) filing = prepare_filing(tax) filing = DB.find_customers |> Orders.for_customers |> sales_tax(2016) |> prepare_filing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment