Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created May 10, 2021 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubukoz/a839309a47023f93df207caa3d46dd66 to your computer and use it in GitHub Desktop.
Save kubukoz/a839309a47023f93df207caa3d46dd66 to your computer and use it in GitHub Desktop.
Names of all subtypes of a Scala ADT
trait TypeNames[A] {
def names: List[String]
}
object TypeNames {
def of[A](implicit ev: TypeNames[A]) = ev.names
implicit def forGenericThing[A, Repr <: Coproduct, Types <: HList](
implicit gen: Generic.Aux[A, Repr],
typeables: coproduct.LiftAll.Aux[Typeable, Repr, Types],
toTraversable: hlist.ToTraversable.Aux[Types, List, Typeable[_]],
): TypeNames[A] = new TypeNames[A] {
def names: List[String] = typeables.instances.toList.map(_.describe)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment