io.scalaland.enumz.internal.EnumeratumMacros.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enumz_native0.5_3 Show documentation
Show all versions of enumz_native0.5_3 Show documentation
Common type class interface for various enums implementations
The newest version!
package io.scalaland.enumz.internal
import io.scalaland.enumz.Enum
import scala.quoted.*
object EnumeratumMacros {
def `enum`[E <: enumeratum.EnumEntry: Type](using q: Quotes): Expr[Enum[E]] = {
import q.*
import q.reflect.*
val E = TypeRepr.of[E]
val enumExpr: Expr[enumeratum.Enum[E]] = Expr.summon[enumeratum.Enum[E]].getOrElse {
report.errorAndAbort(s"Could not find enumeratum.Enum[${E.show}] instance")
}
'{
import scala.language.dynamics
new Enum[E] {
lazy val values: Vector[E] = ${ enumExpr }.values.toVector
def getName(`enum`: E): String = `enum`.toString
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy