0

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.

crak
  • 1,635
  • 2
  • 17
  • 33
  • Probably a duplicated of http://stackoverflow.com/questions/27434302/extract-label-values-from-a-labelledgeneric-instance - tl;dr - `keys.toList.map(_.name)` – Sandro Aug 25 '16 at 16:48
  • Not realy, the context is not the same, and call toList in a function without concrete type, require you to specify implicit. – crak Aug 26 '16 at 09:27

0 Answers0