Simplest way to sum two Lists in Scala?

Another way to simplify:

import Function.tupled
List(1,2).zip(List(5,5)) map tupled {_ + _}

For two lists:

(List(1,2), List(5,5)).zipped.map(_ + _)

For three lists:

(List(1,2), List(5,5), List(9, 4)).zipped.map(_ + _ + _)

For n lists:

List(List(1, 2), List(5, 5), List(9, 4), List(6, 3)).transpose.map(_.sum)

missingfaktor's answer is what I would have recommended, too.

But you could even improve your snippet to get rid of using the clumsy _1, _2:

List(1,2) zip List(5,5) map { case (a, b) => a + b }

Tags:

Scala