Last active
March 31, 2017 12:31
-
-
Save javiervidal/a3dd5a23e3b9ac70d80d7271a7eddfb8 to your computer and use it in GitHub Desktop.
Modules and Named Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Factorial do | |
def of(0), do: 1 | |
def of(n), do: n * of(n-1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Factorial do | |
def of(0), do: 1 | |
def of(n) when n > 0 do | |
n * of(n-1) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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