Until now, we've played with functions that operate on only one type of data (monomorphic functions). Now, we will finally apply our type system knowledge to build functions that work for multiple types. Functions that take type parameters are called polymorphic functions similar to polymorphic methods implemented in an object-oriented hierarchy of classes (subtype polymorphism). For functions in Scala, it is called parametric polymorphism.
Polymorphism and higher order functions
Polymorphic functions
We have already used polymorphic functions when we played with Glass examples in the previous chapter:
sealed trait Glass[+Contents]
case class Full[Contents](c: Contents) extends Glass[Contents]
case object EmptyGlass...