I have a HList
of coproducts that looks like this:
(A :+: B :+: CNil) :: (Foo :+: Bar :+: CNil) :: HNil
This HList
will be a value in my program. E.g.,:
val myhlist: (A :+: B :+: CNil) :: (Foo :+: Bar :+: CNil) :: HNil = ???
I have another HList of coproducts, that looks like this:
(A :+: CNil) :: (Bar :+: CNil) :: HNil
However, this HList will not be a value throughout the program; it only exists in the type level.
I want to zip these two HLists with this zipping function:
def zipFn[A <: Coproduct, B <: Coproduct](a: A)(implicit basis: Basis[A, B]) = {
a.deembed[B]
}
A
is an element from the former HList (which will have values throughout the program), and B
is an element from the latter HList. I want to zip values (A
s) with types (B
s).
Might be a very simple question but somehow I am troubled with this?
Any pointers?
--
My current idea was to use a curried polymorphic function in Shapeless; something like:
object myZipFn extends Poly1 {
implicit def default[A <: Coproduct, B <: Coproduct](implicit basis: Basis[A, B]) = at[A] { a => a.deembed[B] }
}
val curried = Poly.curried(myZipFn)
but doesn't make much sense since default
asks for A and B at the same time.
My idea would be to take in B
(the type with no value) generically first, then return a new function that asks for A
as a value, and then we have both.
Thanks