Why can't tuples in Scala be traversed? -
suppose create tuple6:
val tup = (true, 1 , "hello" , 0.4 , "world" , 0 ) tup: (boolean, int, string, float, string, int) and can access elements of tuple using ._<position> tup._1 , tup._2 , on. why
for (i <- 1 6) println(tup._i) give me error saying
value _i not member of (string, int, boolean, string, double, int) i understand stated tuples not iterable, if ._1 works , shouldn't ._i work same way ?
it boils down type.
what type dynamic accessor such _<position> have? in general case, valid 1 any. in strongly-typed language such scala useless purposes.
the news problem can handled in type-safe manner - see e.g. the hlist-style tuple handling in shapeless.
however, there no such mechanism available in standard scala library (barring heavy metaprogramming such macros).
Comments
Post a Comment