This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |