In Scala, what are the use cases for tuples? In particular why would I use a tuple instead of creating a case class?
example
type Average = Double
type Median = Double
type Quantile = Double
type Min = Double
type Max = Double
type StdDev = Double
def stats(times: Seq[Int]): (Average, Median, Quantile, Min, Max, StdDev)
vs
case class StatResults(average: Double, median: Double, quantile: Double, min: Double, max: Double, stdDev: Double)
def stats(times: Seq[Int]): StatResults
In your example, the case class is clearly a better idea/design. However, one frequent use that I make of tuples is typically when I am handling scala maps, which makes extensive use of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With