【发布时间】:2018-10-16 15:57:00
【问题描述】:
我在继承的遗留系统中无法读取这行 scala。
post("tokens" :: Auth() :: stringBody) { (_: String, token: String) =>
如果需要,我可以在之前和之后发布这些行,但我认为这行本身对 Scala 开发人员有一定的意义。
post方法来自finch库,这里是方法签名和注释:
/**
* A combinator that wraps the given [[Endpoint]] with additional check of the HTTP method. The
* resulting [[Endpoint]] succeeds on the request only if its method is `POST` and the underlying
* endpoint succeeds on it.
*/
def post[A](e: Endpoint[A]): EndpointMapper[A] = new EndpointMapper[A](Method.Post, e)
我假设下划线是一个字符串的全部匹配,但是这个匹配是什么?我假设它与 post 方法中的参数匹配,但是捕获了三个参数和两个东西。
我假设该方法与“令牌”REST 端点值匹配,然后需要一个 Auth 标头并捕获字符串正文。我对双冒号参数在这种情况下的含义感到困惑,因为它在第一次和第二次使用时会表现不同。
【问题讨论】:
-
post 方法的签名是什么?在这种情况下,下划线表示函数的忽略参数。
{ (_: Int, token: String) =>部分是一个以两个字符串作为输入的 lambda 函数的开头。 -
我会用方法的签名和注释更新问题
-
已更新,感谢评论