Scala list of tuples of different size zip issues? -
hi 2 lists follows:
val = list((1430299869,"a",4200), (1430299869,"a",0)) val b = list((1430302366,"b",4100), (1430302366,"b",4200), (1430302366,"b",5000), (1430302366,"b",27017), (1430302366,"b",80), (1430302366,"b",9300), (1430302366,"b",9200), (1430302366,"a",5000), (1430302366,"a",4200), (1430302366,"a",80), (1430302366,"a",443), (1430302366,"c",4100), (1430302366,"c",4200), (1430302366,"c",27017), (1430302366,"c",5000), (1430302366,"c",80))
when used zip 2 lists below :
val c = zip b
it returns results
list(((1430299869,a,4200),(1430302366,b,4100)), ((1430299869,a,0),(1430302366,b,4200)))
not lists of tuples, how can zip above data?
edit
expected results combine of 2 lists :
list((1430299869,"a",4200), (1430299869,"a",0),(1430302366,"b",4100), (1430302366,"b",4200), (1430302366,"b",5000), (1430302366,"b",27017), (1430302366,"b",80), (1430302366,"b",9300), (1430302366,"b",9200), (1430302366,"a",5000), (1430302366,"a",4200), (1430302366,"a",80), (1430302366,"a",443), (1430302366,"c",4100), (1430302366,"c",4200), (1430302366,"c",27017), (1430302366,"c",5000), (1430302366,"c",80))
second edit
i tried :
val d = for(((a,b,c),(d,e,f)) <- (a zip b)if(b.equals(e) && c.equals(f))) yield (d,e,f)
but gives empty results because of (a zip b)
replaced a zip b
a ++ b
shows following error :
constructor cannot instantiated expected type;
so how can matching tuples?
according 2nd edit, need is:
for { (a1,b1,c) <- //rename extracted a1 , b1 avoid confusion (d,e,f) <- b if b1.equals(e) && c.equals(f) } yield (d,e,f)
or:
for { (a1, b1, c) <- (d, `b1`, `c`) <- b //enclosing in backticks avoids capture , matches against defined values } yield (d, b1, c)
zipping won't since need compare tuples in a
tuples in b
, seems.
Comments
Post a Comment