ABSTRACT

Tuple Zipped Type (Advanced) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 10.5 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241

10.5.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 10.5.2 Self-Directed Study . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 10.5.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 10.5.4 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

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 a tuple. That same 3-D point could be represented as a (Double, Double, Double). While this works reasonably well for a 3-D point, it too has some significant limitations. The main limitation is that being a (Double, Double, Double) does not tell you anything about what those three Doubles mean or how it should be used.