Can extractors be customized with parameters in the body of a case statement (or anywhere else that an extractor would be used)?

前端 未结 5 1237
情书的邮戳
情书的邮戳 2020-12-06 10:15

Basically, I would like to be able to build a custom extractor without having to store it in a variable prior to using it.

This isn\'t a real example of how I would

5条回答
  •  一向
    一向 (楼主)
    2020-12-06 11:07

    Late but there is a scalac plugin in one of my lib providing syntax ~(extractorWith(param), bindings):

    x match {
      case ~(parametrizedExtractor(param)) => 
        "no binding"
      case ~(parametrizedExtractor(param), (a, b)) =>
        s"extracted bindings: $a, $b"
    }
    

    https://github.com/cchantep/acolyte/blob/master/scalac-plugin/readme.md

提交回复
热议问题