December 2015
Intermediate to advanced
298 pages
5h 30m
English
In the last chapter, we looked at the decorator pattern and Scala's stackable modifications. Here is another way to use expression decorators. As we have had some curry, let's round it out with ice creams! Quite a feast there is today!
As if an ice cream itself is not enough a temptation, we have toppings as well. We will have nuts, jelly, and honey toppings. Feeling sinful already? Here comes the Scala version:
import scala.language.implicitConversions object IceCreams extends App { sealed trait IceCreamType { // 1 def price: Double } case object Vanilla extends IceCreamType { // 2 val price = 10.0 } case object Mango extends IceCreamType { val price = 20.0 } implicit def iceCreamPriceWrapper(iceCreamType: ...
Read now
Unlock full access