Reader small image

You're reading from  Learning Scala Programming

Product typeBook
Published inJan 2018
Reading LevelBeginner
PublisherPackt
ISBN-139781788392822
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Vikash Sharma
Vikash Sharma
author image
Vikash Sharma

Vikash Sharma is a software developer and open source technology evangelist. He tries to keep things simple, which helps him write clean and manageable code. He has invested a large amount of time learning and implementing Scala code, and he has authored video courses for Scala. He works as a developer at SAP Labs.
Read more about Vikash Sharma

Right arrow

Container types


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...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Scala Programming
Published in: Jan 2018Publisher: PacktISBN-13: 9781788392822

Author (1)

author image
Vikash Sharma

Vikash Sharma is a software developer and open source technology evangelist. He tries to keep things simple, which helps him write clean and manageable code. He has invested a large amount of time learning and implementing Scala code, and he has authored video courses for Scala. He works as a developer at SAP Labs.
Read more about Vikash Sharma