Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. sealed abstract class Item
  2.  
  3. case class Article(description:String,price:Double) extends Item
  4. case class Bundle(description:String,discount:Double,item:Item*) extends Item
  5.  
  6. val composedBundle = Bundle("Father's day special",20.0,
  7. Article("Scala for the Impatient",39.95),
  8. Bundle("Another Distillery Sample",10.0,
  9. Article("Old Potrero Straight Rye Whisky",79.95),
  10. Article("Junipero Gin",32.95)
  11. )
  12. )
  13.  
  14. def price(it:Item):Double = it match {
  15. case Article(_,p) => p
  16. case Bundle(_,disc,its @ _*) => its.map(price _).sum - disc
  17. }
  18.  
  19. println(price(composedBundle))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement