我有两种解决方案,但一种无法编译,我认为另一种可能会更好:
object Foo extends App {
val vectors = List(List(1,2,3), List(2,2,3), List(1,2,2)) //just a stupid example
//transposing
println("vectors = " + vectors.transpose.map (_.sum)) //it prints vectors = List(4, 6, 8)
//folding
vectors.reduce {
case (a, b) => (a zip b) map {
case (x, y) => x + y
}
} //compiler says: missing parameter type for exp. function; arg. types must be fully known
}