So, there are hlists
of options:
val l1 = Option(1) :: Option("str") :: Option(true) :: HNil
val l2 = Option(1) :: {None: Option[String]} :: Option(false) :: HNil
To make a new list, consisting of all matching type objects (of their TypeTags), it is possible using the liftA2
function ( https://stackoverflow.com/a/14456938/1092399 )(notice: there are repetitive types and lots of HNil
objects in a result, but it is not a question):
object eq extends Poly2 {
implicit def neq[A, B](implicit e: A =:!= B) =
at[Option[A], Option[B]] { case (a, b) => (HNil) }
implicit def eq[A, B](implicit t: TypeTag[A], e: A =:= B) =
at[Option[A], Option[B]] {(a, b) => t :: HNil}
}
liftA2(eq)(l1, l2) //> there would be all three types
So now the objective is to skip all empty Option
objects (if we can do this, so there is a chance to build a list of matching all empty Option
objects); we need smth like:
object eqo extends Poly2 {
implicit def neq[A, B](implicit e: A =:!= B) =
at[Option[A], Option[B]] { case (a, b) => (HNil) }
implicit def eq[A, B](implicit t: TypeTag[A], e: A =:= B) =
at[Option[A], Option[B]] {
case(a, None) => HNil
case (None, b) => HNil
case (a, b) => t :: HNil
}
}
liftA2(eqo)(l1, l2) //> result with no String type (should be)
The function above is wrong, cause there happens type erasure (types in a result ~ Product with Serializable with shapeless.HList
).
So the question: is there a way to make such check or it is completely unreal?
p.s. It is a very interesting type of case
in this situation: Product with Serializable with shapeless.HList