[ad_1]
Given a case class A
I can extract its field names with Shapeless using the following snippet:
val fieldNames: List[String] =
import shapeless._
import shapeless.ops.record.Keys
val gen = LabelledGeneric[A]
val keys = Keys[gen.Repr].apply
keys.toList.map(_.name)
This works all nice, but how can I implement this in a more generic manner, so that I can conveniently use this technique for arbitrary classes, like
val fields: List[String] = fieldNames[AnyCaseClass]
Is there a library that already does this for me?
[ad_2]
لینک منبع