ちょっくら質問受けたので作ってみた。これでいいのか?
def list2tuple[T]( list:List[Any] ):T = { ( list match { case Nil => () case a::Nil => Tuple1(a) case a::b::Nil => (a,b) case a::b::c::Nil => (a,b,c) //あとここに、Tuple22まで書きましょうw case _ => throw new Error } ).asInstanceOf[T] }
こんな感じで、全部引数の型指定してつかう↓
list2tuple[(Int,String,Int)]( List(1,"a",2) ) list2tuple[(Int,Int)]( List(1,2) )
もっと良い書き方あったら誰か教えてください。そもそも変換すること自体あまりよくないんだろうけど