Created
May 10, 2021 22:20
-
-
Save kubukoz/a839309a47023f93df207caa3d46dd66 to your computer and use it in GitHub Desktop.
Names of all subtypes of a Scala ADT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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