You can't do this in a typesafe way. Why? Because in general we can't know the length of a list until runtime. But the "length" of a tuple must be encoded in its type, and hence known at compile time. For example, (1,'a',true)
has the type (Int, Char, Boolean)
, which is sugar for Tuple3[Int, Char, Boolean]
. The reason tuples have this restriction is that they need to be able to handle a non-homogeneous types.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…