Thanks https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.0.0 I understand how to button shapeless HLists:
Import some stuff from Shapeless 2.0.0-M1:
import shapeless._ import shapeless.ops.hlist._ import syntax.std.tuple._ import Zipper._
Create two HLists:
scala> val h1 = 5 :: "a" :: HNil h1: shapeless.::[Int,shapeless.::[String,shapeless.HNil]] = 5 :: a :: HNil scala> val h2 = 6 :: "b" :: HNil h2: shapeless.::[Int,shapeless.::[String,shapeless.HNil]] = 6 :: b :: HNil
Pin them:
scala> (h1, h2).zip res52: ((Int, Int), (String, String)) = ((5,6),(a,b))
Now try defining a function that does the same:
scala> def f[HL <: HList](h1: HL, h2: HL) = (h1, h2).zip f: [HL <: shapeless.HList](h1: HL, h2: HL)Unit
The inferred return type is Unit, and indeed, applying f to h1 and h2 does just that:
scala> f(h1, h2) scala>
Is there a way to determine f so that in this case I get ((5,6), (a, b))?
Ultimately, what I'm trying to do is define a function that fastens two HLists and then displays them, choosing either _1 or _2, based on a coin toss, which will give another HL.
object mix extends Poly1 { implicit def caseTuple[T] = at[(T, T)](t => if (util.Random.nextBoolean) t._2 else t._1) }
What works great in REPL:
scala> (h1, h2).zip.map(mix) res2: (Int, String) = (5,b)
But I will try to solve this problem when I try to use it in a function.
Thanks!