Are there any methods included in Scala to convert tuples to lists?

前端 未结 2 1980
深忆病人
深忆病人 2020-12-13 06:03

I have a Tuple2 of List[List[String]] and I\'d like to be able to convert the tuple to a list so that I can then use List.transpose().

2条回答
  •  暖寄归人
    2020-12-13 06:50

    Using Shapeless -

    @ import syntax.std.tuple._
    import syntax.std.tuple._
    @ (1,2,3).toList
    res21: List[Int] = List(1, 2, 3)
    @ (1,2,3,4,3,3,3,3,3,3,3).toList
    res22: List[Int] = List(1, 2, 3, 4, 3, 3, 3, 3, 3, 3, 3)
    

    Note that type information is not lost using Shapeless's toList.

提交回复
热议问题