I would like to apply some functions to fields in a case class. A field that has to be "transformed" is annotated using Annot. I am trying to use Everywhere and a Poly1. At the moment I am able to apply the transformation function to all the fields but I am not able to "pass" the information about the annotated fields.
import shapeless._
object Test {
case class Annot(
fieldType: String
) extends scala.annotation.StaticAnnotation
case class Address(
street: String,
isCapital: Boolean
)
case class Person(
@Annot("TypeA") lastName: String,
firstName: String,
isTall: Boolean,
address: Address
)
def transformationMethod(element: String, fieldType: String): String = ???
object Transformer extends Poly1 {
implicit def someStringCase: Case.Aux[String, String] = at {
case e => {
transformationMethod(e, "Name")
}
}
//other methods ..
}
def traverseAndModify[T](
expr: T
)(implicit e: Everywhere[Transformer.type, T] { type Result = T }): T = e(expr)
//Usage
val person = Person("LASTName", "FIRSTName", true, Address("My home address", true))
val modified : Person = traverseAndModify[Person](person)
}
I am wondering how to modify "everywhere" to also pass annotations to the poly function. So I would like something similar to this in the Poly
object AnnotatedTransformer extends Poly1 {
implicit def someStringCase: Case.Aux[(String, Some[Annot]), String] = at {
case (e, Some(Annot(fieldType))) => {
transformationMethod(e, fieldType)
}
}
}