build.sbt
libraryDependencies += "com.github.xuwei-k" %% "shapeless-annotation" % "version"
scalacOptions ++= {
scalaBinaryVersion.value match {
case "2.13" =>
Seq("-Ymacro-annotations")
case _ =>
Nil
}
}
import shapeless_annotation.ShapelessGeneric
@ShapelessGeneric // macro annotation
case class A1(x: Int, y: String, z: Boolean)
↓
import shapeless.Generic
import shapeless.HNil
import shapeless.::
case class A1(x: Int, y: String, z: Boolean)
object A1 {
// generate by macro annotation 😄
implicit val genericInstance: Generic.Aux[A1, Int :: String :: Boolean :: HNil] =
Generic.materialize[A1, Int :: String :: Boolean :: HNil]
}