Consider the following:
sealed trait baseData {
def weight: Int
def priority: Int
}
case class data1(override val weight: Int, override val priority: Int) extends baseData
How would I define a function with the following signature that transforms data1
into an HList?
def toHlist[A <: baseData] (data: A) = {}
I want to pass in a trait instance into the toHlist
function instead of the actual case class because there will be more than one case class extending the trait. I also don't want to hardcode any fields; I'm looking for a totally generic solution.
I'm sure this is doable with the Shapeless library, but haven't been able to figure out how.
EDIT
toHList
needs to be able to handle a baseData
pointer to a case class instance, as so:
val data: baseData = data1(1,2)
toHlist(data)
The reason for this is that we will have more than one case class extending baseData
, and we will now know which one to pass to toHlist
until run time.