scala - How to merge / combine list of tuples of diffrent sizes -


i have following 2 lists-

list(("abc",1,10),("pqr",1,10)) list((1,"abc",3940903,0.0),(2,"pqr",1234,3.0)) 

i want following output

list(("abc",1,10,1,"abc",3940903,0.0),("pqr",1,10,2,"pqr",1234,3.0) 

i tried out concat, ::: didn't worked me.

how above output using scala??

you can not merge tuples directly in scala. there 2 ways achieve it

using shapeless

val = list(("abc", 1, 10), ("pqr", 1, 10))    val b = list((1, "abc", 3940903, 0.0), (2, "pqr", 1234, 3.0)) val zippedlist = zip b  import shapeless.syntax.std.tuple._ zippedlist.map { case (a, b) => ++ b }  //list((abc,1,10,1,abc,3940903,0.0), (pqr,1,10,2,pqr,1234,3.0)) 

this method works on arbitrary size tuples

using no external library

zippedlist.map { case ((a,b,c), (p,q,r,s)) => (a,b,c,p,q,r,s) } //list((abc,1,10,1,abc,3940903,0.0), (pqr,1,10,2,pqr,1234,3.0)) 

the tuples should have fixed arity work


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -