小编dad*_*n89的帖子

如何使“无处不在”的注释也传递给poly函数

我想将一些函数应用于case类中的字段。使用Annot注释必须“转换”的字段。我正在尝试使用Everywhere和Poly1。目前,我可以将转换功能应用于所有字段,但是无法“传递”有关带注释字段的信息。

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 = …
Run Code Online (Sandbox Code Playgroud)

annotations scala shapeless

5
推荐指数
0
解决办法
93
查看次数

标签 统计

annotations ×1

scala ×1

shapeless ×1