Skip to content

Instantly share code, notes, and snippets.

View frehn's full-sized avatar

Daniel Weller frehn

  • Vienna, Austria
View GitHub Profile
@frehn
frehn / customer.scala
Last active September 13, 2019 09:17
DUs in Scala
sealed trait Customer
case class RegisteredCustomer(id : String) extends Customer
case class EligibleRegisteredCustomer(id : String) extends Customer
case class Guest(id: String) extends Customer
def calculateTotal(customer: Customer)(spend: Double) = {
val discount = customer match {
case EligibleRegisteredCustomer(_) if spend >= 100.0 => spend * 0.1
case _ => 0.0