I'm essentially looking for the opposite of the type class Prepend[A, B]
.
If I have something like:
type A = String :: Int :: HNil
type B = Boolean :: Double :: HNil
val a: A = "a" :: 1 :: HNil
val b: B = false :: 2.1 :: HNil
scala> val ab = a ++ b
ab: shapeless.::[String,shapeless.::[Int,shapeless.::[Boolean,shapeless.::[Double,shapeless.HNil]]]] = a :: 1 :: false :: 2.1 :: HNil
I have an HList
a
of type A
and an HList
b
of type B
, I can find a prepend: Prepend[A, B]
such that I can concatenate them with a ++ b
.
But if I have an HList
ab
of type prepend.Out
, how can I extract the original A
and B
? I can't seem to find a type class that does the job, and perhaps there isn't one. It seems like I would need something like trait Cut[A <: HList, B <: HList, c <: HList]
that witnesses that C
has been created by pre-pending A
to B
, though I'm not sure how I would go about generating witnesses.
Very roughly like:
def Cut[A <: HList, B <: HList, C <: HList](c: C)(implicit cut: Cut[A, B, C]): (A, B) = ???