Last active
September 13, 2019 09:17
-
-
Save frehn/661f525ca7361359f69c800203939eb1 to your computer and use it in GitHub Desktop.
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