Created
February 12, 2019 23:06
-
-
Save Apelsinka223/ab682b3302bf81ed4c6eaa760adc81ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MyApp.Calculator do | |
def convert(amount, currency_from, currency_to) do | |
with {:ok, rate_currency_from} <- MyApp.Rates.get_current_rate(currency_from), | |
{:ok, rate_currency_to} <- MyApp.Rates.get_current_rate(currency_to), | |
value = amount * rate_currency_from / rate_currency_to do | |
{:ok, value} | |
end | |
end | |
end | |
defmodule MyApp.Rates do | |
def get_current_rate(currency) do | |
# do external API requests | |
{:ok, result} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment