How to sum a list of tuples in Scala

1 Answer

0 votes
object MyClass {
    def main(args: Array[String]): Unit = {
        val list = List((1, 2), (1, 2), (3, 4), (3, 4))

        val sum = list.unzip match {case (t1, t2) => (t1.sum, t2.sum)}

        println(sum)
    }
}
     
     
     
     
/*
run:
     
(8,12)
     
*/

 



answered Jun 3, 2021 by avibootz

Related questions

...