Get field names and values from LablelledGenerics of a case class

1.8k views Asked by At

I try to have Seq[String], containing the fields name of a case class And another Seq[String] containing values of case class. In a generic way. I think I will have to map values with a Poly1 function to have the Arbitrary type => String.

But now, I'm not able to extract keys and values form LabelledGenerics.

def apply[T,R <: HList](value : T)(implicit gen: LabelledGeneric.Aux[T, R],
                      keys : Keys[R],
                      valuesR : Values[R]
                      ) {
       val hl = gen.to(value) 
       val keys = hl.keys ...
       val values = hl.values.map ...
}

I'm not sure if I have to ask for keys and values implicit or if it's possible to have this from the LabelledGeneric.

I have tried to map the following Poly over keys to have a hlist of string. But it's seems keys are not Witness

object PolyWitnesToString extends Poly1 {
  implicit def witnessCase = at[Witness]{ w => w.toString}
}

I'm a little bit lost now.

0

There are 0 answers