You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
println(s"Our planet is $distance kilometers from the sun")
68
+
case _ =>
78
69
}
79
70
```
80
71
81
-
Or, in 'for' comprehension.
72
+
Or, in `for` comprehension:
82
73
83
74
```tut
84
75
val numPairs = List((2, 5), (3, -7), (20, 56))
85
-
86
76
for ((a, b) <- numPairs) {
87
-
88
77
println(a * b)
89
-
90
78
}
91
79
```
92
80
93
-
The value () of type Unit is conceptually the same as the value () of type Tuple0. There can only be one value of this type since it has no elements.
81
+
## Tuples and case classes
82
+
83
+
Users may sometimes find it hard to choose between tuples and case classes. Case classes have named elements. The names can improve the readability of some kinds of code. In the planet example above, we might define `case class Planet(name: String, distance: Double)` rather than using tuples.
94
84
95
-
Users may sometimes find hard to choose between Tuples and case classes. As a rule, case classes are preferred choice if elements carry more meaning.
0 commit comments