Accessing Tuples in Scala
Scala seems to be like a gold mine, the more you dig into, the more you get. While you deal with tuples, when you want to access the elements of a tuple, you have to use the default numbering given to you by the Scala compiler. Say for example., you have a tuple as defined below:
1val myTuple = (31, "Joesan", "M")
2println(myTuple._1) // To access the first element
What you could alternatively do is to decompose the tuple into its constituent elements as below:
1val myTuple = (31, "Joesan", "M")
2val (age, name, sex) = myTuple
3println(age) // To access the age set in myTuple
4println(name) // Did you get the idea...
I find this way of decomposing the tuple and accessing the elements from it using some meaningful names much more elegant than fiddling around with numbers which unfortunately does not say much on what you are reading.