Convert Vector to Tuple scala -


is possible convert vector of heterogeneous vectors list of tuple3 in scala

i.e.

vector(vector(1,"a","b"),vector(2,"b","c")) list(tuple3(1,"a","b"),tuple3(2,"b","c")) 

explicitly convert every inner vector tuple3:

vector.map {     case vector(f, s, t) => tuple3(f, s, t) }.tolist 

if have vectors of variadic size can use more general approach:

def totuple(seq: seq[_]): product = {   val clz = class.forname("scala.tuple" + seq.size)   clz.getconstructors()(0).newinstance(seq.map(_.asinstanceof[anyref]): _*).asinstanceof[product] }  vector.map(totuple).tolist 

but has restriction: max length of vectors 22.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -