September 2018
Intermediate to advanced
398 pages
9h 43m
English
Type the following in the Scala Console to get more familiar with tuples. Feel free to experiment with different types and sizes of tuples:
scala> val tuple3 = (1, "hello", 2.0)tuple3: (Int, String, Double) = (1,hello,2.0)scala> tuple3._1res1: Int = 1scala> tuple3._2res2: String = helloscala> val (a, b, c) = tuple3a: Int = 1b: String = helloc: Double = 2.0
You can create tuples of any length up to 22, and access their elements using _1, _2, and so on. You can also declare several variables in one go for each element of the tuple.
Read now
Unlock full access