Hi Srinivas,
If you materialise the values in memory with .toList you are indeed going to exceed your memory. However you don't need to do that. You can still iterate over your values with a for loop and accumulate the values you want (for count and sum):
list.mapValues { values =>
var (count, sum) = (0, 0)
values.foreach { case (v1, v2, v3) =>
count += 1
sum += v3
}
(count, sum)
}
For the median, I don't know what's the best approach. Intuitively I would build a frequency map: Map[V2, Int] in the for loop to count how many times a value v2 has been seen. And from this map deduce the mean value. There might be a better way but I don't see which one if you have a large number of values.
E.