shapeless Supports displaying and collapsing tuples through an intermediate HList ,
Sample REPL Session,
scala> import shapeless._ ; import Tuples._ import shapeless._ import Tuples._ scala> object double extends (Int -> Int) (_*2) defined module double scala> (3, 4).hlisted.map(double).tupled res0: (Int, Int) = (6,8)
If the elements of a tuple are of different types, you can map the polymorphic function to specific types of cases,
scala> object frob extends Poly1 { | implicit def caseInt = at[Int](_*2) | implicit def caseString = at[String]("!"+_+"!") | implicit def caseBoolean = at[Boolean](!_) | } defined module frob scala> (23, "foo", false, "bar", 13).hlisted.map(frob).tupled res1: (Int, String, Boolean, String, Int) = (46,!foo!,true,!bar!,26)
Update
In the form of shapeless 2.0.0-M1 , binding to tuples directly is supported. The above examples now look like this:
scala> import shapeless._, poly._, syntax.std.tuple._ import shapeless._ import poly._ import syntax.std.tuple._ scala> object double extends (Int -> Int) (_*2) defined module double scala> (3, 4) map double res0: (Int, Int) = (6,8) scala> object frob extends Poly1 { | implicit def caseInt = at[Int](_*2) | implicit def caseString = at[String]("!"+_+"!") | implicit def caseBoolean = at[Boolean](!_) | } defined module frob scala> (23, "foo", false, "bar", 13) map frob res1: (Int, String, Boolean, String, Int) = (46,!foo!,true,!bar!,26)