Skip to content

Instantly share code, notes, and snippets.

@michaeldiamant
Created October 7, 2012 21:31
Show Gist options
  • Select an option

  • Save michaeldiamant/3849665 to your computer and use it in GitHub Desktop.

Select an option

Save michaeldiamant/3849665 to your computer and use it in GitHub Desktop.
Represent a price with a case class
case class UsdPrice(value: BigDecimal) {
def +(p: UsdPrice) = UsdPrice(value + p.value)
def -(p: UsdPrice) = UsdPrice(value - p.value)
}
case class EurPrice(value: BigDecimal) {
def +(p: EurPrice) = EurPrice(value + p.value)
def -(p: EurPrice) = EurPrice(value - p.value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment