Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created May 19, 2021
Embed
What would you like to do?
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