Skip to content

Instantly share code, notes, and snippets.

@lu4nm3
Created May 15, 2020 08:28
Show Gist options
  • Save lu4nm3/b3b0d62ddfe23b7cdc798e99db0ccc80 to your computer and use it in GitHub Desktop.
Save lu4nm3/b3b0d62ddfe23b7cdc798e99db0ccc80 to your computer and use it in GitHub Desktop.
object Cake {
implicit val price: Price[Cake] = new Price[Cake] {
def price(cake: Cake): Double = cake.price
}
}
object Apple {
val PricePerLb: Double = 3.0
implicit val price: Price[Apple] = new Price[Apple] {
def price(apple: Apple): Double = PricePerLb * apple.weightLbs
}
}
object Shampoo {
implicit val price: Price[Shampoo] = new Price[Shampoo] {
def price(shampoo: Shampoo): Double = shampoo.price
}
}
// etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment