Given something like
val list: List[List[Int]] = List(List(5), List(1), List(2), List(3), List(4), List(5, 1), List(5, 2), List(5, 3))
List(5,1,2,3,4,6,7,8)
You can use a map
to do this
list.map(_.sum)
or
list.map(innerList => sum(innerList))
Instead of the custom sum function you could use standard lib sum function
scala> val lists = List(List(1, 2), List(3, 4))
lists: List[List[Int]] = List(List(1, 2), List(3, 4))
scala> lists.map(_.sum)
res11: List[Int] = List(3, 7)