Skip to content

Instantly share code, notes, and snippets.

@Apelsinka223
Created February 12, 2019 23:06
Show Gist options
  • Save Apelsinka223/ab682b3302bf81ed4c6eaa760adc81ed to your computer and use it in GitHub Desktop.
Save Apelsinka223/ab682b3302bf81ed4c6eaa760adc81ed to your computer and use it in GitHub Desktop.
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