Tutorial by Examples

A tuple is a heterogeneous collection of two to twenty-two values. A tuple can be defined using parentheses. For tuples of size 2 (also called a 'pair') there's an arrow syntax. scala> val x = (1, "hello") x: (Int, String) = (1,hello) scala> val y = 2 -> "world" y:...
Tuples are often used within collections but they must be handled in a specific way. For example, given the following list of tuples: scala> val l = List(1 -> 2, 2 -> 3, 3 -> 4) l: List[(Int, Int)] = List((1,2), (2,3), (3,4)) It may seem natural to add the elements together using im...

Page 1 of 1