Skip to content

Instantly share code, notes, and snippets.

@j5ik2o
Last active February 25, 2019 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j5ik2o/c344a5ceebe8fa7b7be0e43e66d90b60 to your computer and use it in GitHub Desktop.
Save j5ik2o/c344a5ceebe8fa7b7be0e43e66d90b60 to your computer and use it in GitHub Desktop.
case class Money(amount: BigDecimal,
currency: Currency) {
def plus(other: Money): Money = {
require(currency == other.currency)
new Money(amount = amount.add(other.amount), currency)
}
}
case class Money(private var _amount: BigDecimal,
private var _currency: Currency) {
def amount = _amount
def currency = _currency
def plus(other: Money): Unit = {
require(currency == other.currency)
amount = amount.add(other.amount)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment