Если вы хотите просто написать усредненный метод, это можно сделать за одну итерацию.
ОБНОВЛЕНИЕ:
def average[T](ls: List[T])(implicit num: Numeric[T]): Float = {
val (sum, length) =
ls.foldLeft((0.0f, 0))({ case ((s, l), x) => (num.toFloat(x) + s, 1 + l) })
sum / length
}
val map = Map[String, List[(Int, String, Float)]](
"Education Route (GU)" -> List(
(1, "University Of Strawberry", 0.65f),
(2, "City Of Cabbage College - Riverside Camp", 1.4f),
(3, "School of Sims", 3.9f),
(4, "Science Centre", 0.7f),
(5, "University of Grapes", 2.4f),
(6, "The Mushroom Library", 1.9f),
(7, "School Of Fruit", 0.9f),
(8, "Royal Conservatoire Of Melons", 0.75f),
(9, "GU", 0.6f)
)
)
val distances = map.mapValues(_.map(_._3)).getOrElse("Education Route (GU)", List.empty)
val steps = map.mapValues(_.map(_._1)).getOrElse("Education Route (GU)", List.empty)
val averageDistance = average[Float](distances)
val averageSteps = average[Int](steps)
println(s"Average distance: $averageDistance")
println(s"Average steps: $averageSteps")
Scast ie выборка здесь