Slide 21
Slide 21 text
Syntax: “context bound”
let's define something that works across the whole typeclass:
implicit def ListIsSerializable[T]
(implicit ev: Serializable[T]) = ...
can be shortened to:
implicit def ListIsSerializable[T : Serializable] =
new Serializable[List[T]] {
def ser(xs: List[T]) =
xs.map(serialize(_))
.mkString("List(", ",", ")") }
scala> serialize(List(Person("Seth", 40),
Person("Kaarin", 43)))
res1: String = List(Person(Seth,40),Person(Kaarin,43))