Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created August 14, 2017 16:07
Show Gist options
  • Save deque-blog/9ee91432af94905cfbb5b3da4fbcb4e5 to your computer and use it in GitHub Desktop.
Save deque-blog/9ee91432af94905cfbb5b3da4fbcb4e5 to your computer and use it in GitHub Desktop.
evalMoneyIn :: (Conversion -> Maybe Rate) -> MoneyBag -> Currency -> Maybe Money
evalMoneyIn findRate (MoneyBag m) refCurrency = do
let convert (curr, amount) = (* amount) <$> findRate (curr, refCurrency)
amounts <- mapM convert (M.toList m)
pure $ Money { amount = sum amounts, currency = refCurrency }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment