Chapter 10
Case Classes
One of the things that you should have noticed by this point is that there are times when it can be helpful to group pieces of data together. We have seen two ways that we can do this. If all the data is the same type, you could use something like an Array or a List. The downside of this is that the compiler can not check to make sure that you have the right number of elements. For example, if you want a point in 3-D with x, y, and z coordinates then you would need an Array[Double] that has three elements in it. Having more or less could cause the code to break and Scala would not be able to check for that until the program was running. The alternative, which also works if the types of the values are different, is to use ...
Get Introduction to the Art of Programming Using Scala now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.