Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created May 19, 2021 12:59
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/5fe00d447ef0f80dbbad68324b390a1e to your computer and use it in GitHub Desktop.
Save kubukoz/5fe00d447ef0f80dbbad68324b390a1e to your computer and use it in GitHub Desktop.
trait Labels[S] {
def label(v: S): String
}
object Labels {
import scala.deriving.*
import scala.compiletime.*
inline def derived[T](using s: Mirror.SumOf[T]): Labels[T] =
a => summonAll[scala.Tuple.Map[s.MirroredElemLabels, ValueOf]].toList(s.ordinal(a)).asInstanceOf[ValueOf[String]].value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment