Skip to content

Instantly share code, notes, and snippets.

@lu4nm3
Created May 16, 2020 19:58
Show Gist options
  • Save lu4nm3/b5a63a72a59d6a67e79eddf50a7f8c48 to your computer and use it in GitHub Desktop.
Save lu4nm3/b5a63a72a59d6a67e79eddf50a7f8c48 to your computer and use it in GitHub Desktop.
object Item {
implicit val price: Price[Item] = new Price[Item] {
def price(item: Item): Double = item match {
case cake: Cake => Cake.price.price(cake)
case baguette: Baguette => Baguette.price.price(baguette)
case apple: Apple => Apple.price.price(apple)
case orange: Orange => Orange.price.price(orange)
case shampoo: Shampoo => Shampoo.price.price(shampoo)
case toothPaste: ToothPaste => ToothPaste.price.price(toothPaste)
}
}
}
object Fruit {
implicit val price: Price[Fruit] = new Price[Fruit] {
def price(fruit: Fruit): Double = fruit match {
case apple: Apple => Apple.price.price(apple)
case orange: Orange => Orange.price.price(orange)
}
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment