We've seen Scala's class hierarchy, hence we are aware of many collection types such as List
, Set
, and Map
. What's different about these types along with types such as Option
and Either
, is that they all expect you to provide a type and then instantiate. We call List
as a container type because it works that way. We use a list to contain elements of a certain data type. Similarly, we can think of an Option
as a binary containerized type, as Option
can be some value or None
. The Either
type goes the same way. In Scala, when we create such container types, we tend to use a type parameter to declare and provide a concrete type, such as String
,Int
, Boolean, and so on when we instantiate. Take a look how Option
is declared in Scala (more on Option
and Either
types in the next chapter):
sealed abstract class Option[+A] extends Product with Serializable
It takes a type parameter A
. It's possible to provide more than one type parameter if your type expects more than one type...