【发布时间】:2014-07-06 03:52:15
【问题描述】:
这完全是一个 Scala 问题,但它是在 PlayFramework Action 的上下文中:
Action 采用 (play.api.mvc.Request => play.api.mvc.Result) 形式。然后你会传递一个像这样的块:
{ request =>
Ok(views.html.index("Your new application is ready."))
}
现在我已经定义了一个具有相同签名的函数。一个有隐式请求,一个没有隐式请求。
def WithUser2(request: Request[AnyContent])(block: (Request[AnyContent]) => Result):Result = {
block(request)
}
def WithUser3(block: (Request[AnyContent]) => Result)(implicit request: Request[AnyContent]):Result = {
block(request)
}
我现在这样称呼它(2 个版本):
def index2 = Action { implicit request => WithUser2(request) { request =>
Ok(views.html.index("Your new application is ready. " ))
}}
def index3 = Action ( implicit request => WithUser3 { request =>
Ok(views.html.index("Your new application is ready. " ))
})
有没有办法直接将我的函数附加到 Action 上?我的意思是没有在 WithUserX 之前放置 implicit request => 以便我的函数直接替换 Action 之后的完整块?现在我的函数在块内,我认为这就是我需要转发请求的问题。所以我需要一种方法来摆脱我的功能周围的障碍。
【问题讨论】:
标签: scala playframework functional-programming