Zip multiple sequences

后端 未结 7 1720
眼角桃花
眼角桃花 2020-12-06 09:20

I am trying to zip multiple sequences to form a long tuple:

val ints = List(1,2,3)
val chars = List(\'a\', \'b\', \'c\')
val strings = List(\"Al         


        
7条回答
  •  醉梦人生
    2020-12-06 09:42

    I share Jesper's opinion that this is not possible in general, since each tuple arity is represented as separate class in source code, so you have to write separate code to access them unless using a code generator.

    But I want to add another possible solution. If you want to preserve the typing of your tuple entries, but are otherwise interested in a more collection-like type, maybe HLists (heterogenous lists) are for you. You can google hlist scala for implementations and explanations.

提交回复
热议问题