Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala - use cases for tuples?

Tags:

scala

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
like image 512
tekumara Avatar asked Nov 01 '22 03:11

tekumara


1 Answers

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.

like image 192
nsanglar Avatar answered Nov 15 '22 05:11

nsanglar