For an example use in your question, this is actually very simple:
import shapeless._ class NameHelper[A] { def apply[C <: Coproduct, K <: HList]()(implicit gen: LabelledGeneric.Aux[A, C], keys: ops.union.Keys.Aux[C, K], toSet: ops.hlist.ToTraversable.Aux[K, Set, Symbol] ): Set[String] = toSet(keys()).map(_.name) } def names[A] = new NameHelper[A]
And then:
scala> names[Traity]() res0: Set[String] = Set(Bar, Baz, Foo)
(I use Set , since the order you receive is only alphabetical - it is currently not possible to list constructors in the order of declaration, although I personally would prefer this .
If you want a more general answer, adapting the code in the question that I linked above should not be too bad - I would be happy to add it here later.
Travis brown
source share