Last active
September 13, 2019 09:17
Star
You must be signed in to star a gist
DUs in Scala
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 | |
} | |
spend - discount | |
} | |
val john = EligibleRegisteredCustomer("John") | |
val assertJohn = (calculateTotal (john) (100.0)) == 90.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment