This file contains hidden or 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
trait PerishableLike[A] { | |
def expired: Boolean | |
} | |
case class PerishableLikeBaguette(b: Baguette) extends PerishableLike[Baguette] { | |
def expired: Boolean = ??? | |
} | |
case class PerishableLikeCroissant(c: Croissant) extends PerishableLike[Croissant] { | |
def expired: Boolean = ??? |
This file contains hidden or 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
trait DailyOrderService { | |
def needsReplacing(perishables: List[Perishable]): List[Perishable] = { | |
perishables.filter(_.expired) | |
} | |
} |
This file contains hidden or 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
trait Perishable { | |
def expired: Boolean | |
} | |
case class Baguette() extends Perishable { | |
def expired: Boolean = ??? | |
} | |
case class Croissant() extends Perishable { | |
def expired: Boolean = ??? |
This file contains hidden or 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
val doubles = new Set[Double]() | |
doubles.add(1.0) | |
doubles.add(3.0) | |
scala> doubles.get(0) | |
res1: Double = 1.0 | |
val strings = new Set[String]() | |
strings.add("one") | |
strings.add("two") |
This file contains hidden or 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
trait Set[A] { | |
def get(index: Long): A | |
def add(value: A): Set[A] | |
} |
This file contains hidden or 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
trait DoubleSet { | |
def get(index: Long): Double | |
def add(value: Double): Set | |
} | |
trait StringSet { | |
def get(index: Long): String | |
def add(value: String): Set | |
} |
This file contains hidden or 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
val ints = new Set() // assuming Set was implemented | |
ints.add(1.0) | |
ints.add(3.0) | |
scala> ints.get(0) | |
res0: Any = 1.0 | |
scala> ints.get(0).asInstanceOf[Double] | |
res1: Double = 1.0 |
This file contains hidden or 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
trait Set { | |
def get(index: Long): Any | |
def add(value: Any): Set | |
} |
This file contains hidden or 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
trait Set { | |
def get(index: Long): ??? | |
def add(value: ???): Set | |
} |
This file contains hidden or 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
def order(restaurant: Restaurant): String = { | |
restaurant.menu | |
} |