I am trying to do something like below, that is, process an HList
recursively by pattern matching the head & tail, each time passing the head to a generic function.
import shapeless._
trait MyTrait {
def myFunc[T](x: String => T): Boolean
def iter(myHList: HList, acc: List[Boolean]): List[Boolean] = {
myHList match {
case HNil => acc
case head :: tail => myFunc(head) :: iter(tail, acc)
}
}
}
The problem is that the head that I get from matching is of type Any
rather than the type of what I put into the HList
. I want the function that takes head as an argument to have the correct type parameter T
.
Is this possible? Maybe with some other means besides Shapeless?