I am writing a combinator that takes in an HList of Option[A] :: Option[AA] :: Option[AAA]... etc.
It also takes a functionf of type A,AA, AAA,... => U. And it returns U. How do I encode the type signature for my combinator? I need to assume my A, AA, AAA are also Monoids so if my options are None, I can call on Monoid zero to create values for f. I am new to shapeless so thank you!
This is what I have so far, but I am missing a lot of constraints.
- Every element of
His anOption[A], Option[AA], ... A, AA, AAAare all Monoids.- The
HListD is just the same asHwithout the Option.
def combinator[H <: HList, D <: HList, U](in: H, f : D => U) : U =
f(in map {
case None : Option[A] => implicitly[Monoid[A]].zero
case Some(v) => v
})