0

I have two lists of case classes of the same type:

case class ScoreOutput = (id: String, runDate: String, score: Double)
val originalScores: List[ScoreOutput] = List(
    ScoreOutput(1, "09-21", 5.0), 
    ScoreOutput(2, "09-21", 3.0),
    ScoreOutput(3, "09-21", 2.0)
)

val currentScores: List[ScoreOutput] = List(
    ScoreOutput(1, "10-01", 20.0), 
    ScoreOutput(2, "10-01", 1.0),
    ScoreOutput(3, "10-01", 18.0)
)

I need to combine the two lists into a new list of a new type

case class ScoreComparison(name: String, originalDate: String, currentDate: String, scoreChange: Double)

val scoreDiff: List[ScoreComparison] = // concatenate two lists, groupby name and fold two lists into new type? 

where scoreDiff would be

List(
    ScoreComparison(1, "09-21", "10-01", 15.0), 
    ScoreComparison(2, "09-21", "10-01", -2.0), 
    ScoreComparison(3, "09-21", "10-01", 16),
    )

what is the best way to accomplish this? I was going to use the method in this answer https://stackoverflow.com/a/45809767/7948380 but I need to keep track of which value in the group by is from the originalScores list and which is from the currentScores list. If I concatenate the lists like this (originalScores ++ currentScore) and then do a groupBy on the concatenated list, am I guaranteed the values in the group by will be in order they appeared in the concatenated list (meaning, will the first item of the groupBy always represent the value from originalScores?

jboges
  • 141
  • 1
  • 10

0 Answers0