Created
July 8, 2021 19:01
-
-
Save jeroenr/e8a0a9e2ecf6c005b733a63e5d1863cb to your computer and use it in GitHub Desktop.
Revisions
-
jeroenr created this gist
Jul 8, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ enum class Currency { USD, EUR } data class Money( val amount: BigDecimal, val currency: Currency, ) { val largerThanZero = amount > BigDecimal.ZERO fun add(o: Money): Money { if(currency != o.currency) throw IllegalArgumentException() return Money(amount.add(o.amount), currency) } fun convert(exchangeRate: ExchangeRateDto): Money { return Money(amount.multiply(exchangeRate.rate), exchangeRate.currency) } }