Scala:使用带有隐式期望字符串上下文的字符串参数

时间:2016-07-20 12:45:41

标签: scala implicit

我已实施此解决方案: https://stackoverflow.com/a/23115778/4631376 (第二个带隐式类) 我试图使用" ci"使用字符串参数而不是文字字符串

implicit class CaseInsensitiveRegex(sc: StringContext) {
   def ci = ("(?i)" + sc.parts.mkString).r
}

 def Refiner(uid: String) = new ActionRefiner[Input, Output] {
     override protected def refine[A](request: Input[A]): Future[Either[Result, Output[A]]] = {
       uid match {
            case ci"${request.auid}" => Future.successful(Right(new Output[A](request.auid, request)))
  }
}

}

但它似乎没有用,因为字符串上下文" sc"是空的。 它应该包含" request.auid"

的内容

它适用于文字字符串(发送内容,如" abcabc")。

想法?

1 个答案:

答案 0 :(得分:0)

普通提取器看起来像应用case X(x)但不是取值,而是绑定名称x。当你的插值被去掉时也一样。

请参阅the scala hacking bloghow to exploit Dynamic for parameterized extractors