I have a vector of tuples
val l = for {i <- 1 to 5} yield (i,i*2)
Vector((1,2), (2,4), (3,6), (4,8), (5,10))
and I'd like to sum it in the following way:
l.reduce((x,y) => (x._1+y._1, x._2+y._2))
(15,30)
but with use of pattern matching.
I know how to do it if the function gets only one parameter, ie: l.map({case(a,b)=>a+b})
, but I can't get it to work with two parameters. this is what I tried to do:
l.reduce({(case(a,b),case(c,d))=>(a+c,b+d)})
but that won't work.
So my question is, how can I unpack 2 tuples that come as a function parameters?