メソッドには次のようなコードを含めることができることを理解しています。
def m(p1:Int => Int) ...
つまり、このメソッドは Int を返す関数 p1 を取ります
しかし、プレイをブラウジングしながら!フレームワーク コード 判読できないメソッドを持つトレイトを見つけました:
trait Secured {
def username(request: RequestHeader) = request.session.get(Security.username)
def onUnauthorized(request: RequestHeader) = Results.Redirect(routes.Auth.login)
def withAuth(f: => String => Request[AnyContent] => Result) = {
Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
}
/**
* This method shows how you could wrap the withAuth method to also fetch your user
* You will need to implement UserDAO.findOneByUsername
*/
def withUser(f: User => Request[AnyContent] => Result) = withAuth { username => implicit request =>
UserDAO.findOneByUsername(username).map { user =>
f(user)(request)
}.getOrElse(onUnauthorized(request))
}
}
とはf: User => Request[AnyContent] => Result
どういう意味ですか? 一見すると、r
Request 型の関数を返すメソッドのように見えます。r
を返しますResult
。
これは正しい仮定ですか?