https://github.com/playframework/playframework/blob/561f4921e5da477658b8e6b34bd48292b42ac9fe/core/play/src/main/scala/play/api/mvc/Action.scala#L360C2-L428C92
There are some Action construct methods.
def apply(block: R[B] => Result): Action[B] =
def apply(block: => Result): Action[AnyContent] =
def async(block: => Future[Result]): Action[AnyContent] =
def async(block: R[B] => Future[Result]): Action[B] =
def async[A](bodyParser: BodyParser[A])(block: R[A] => Future[Result]): Action[A] =
some common use cases request implicit variable not reference explicit in Action.
class MyController {
def hello(id: Int): Action[AnyContent] = Action { implicit request =>
obj.myMethodImplicitRequest(id)
}
}
def myMethodImplicitRequest(id: Int)(implicit request: Request[?]) =
I think this is proper use case Scala 3 context function.
We can remove boilerplate implicit request => by context function.
https://docs.scala-lang.org/scala3/reference/contextual/context-functions.html
class MyController {
+ def hello(id: Int): Action[AnyContent] = Action.someContextFunctionMethod {
- def hello(id: Int): Action[AnyContent] = Action { implicit request =>
obj.myMethodImplicitRequest(id)
}
}
We should add new name method in src/main/scala-3 instead of apply or async overloads but I can’t think of good method name.
WDYT?
I have added some context function methods in scalikejdbc because there is similar use case
https://github.com/playframework/playframework/blob/561f4921e5da477658b8e6b34bd48292b42ac9fe/core/play/src/main/scala/play/api/mvc/Action.scala#L360C2-L428C92
There are some
Actionconstruct methods.some common use cases
requestimplicit variable not reference explicit inAction.I think this is proper use case Scala 3 context function.
We can remove boilerplate
implicit request =>by context function.https://docs.scala-lang.org/scala3/reference/contextual/context-functions.html
class MyController { + def hello(id: Int): Action[AnyContent] = Action.someContextFunctionMethod { - def hello(id: Int): Action[AnyContent] = Action { implicit request => obj.myMethodImplicitRequest(id) } }We should add new name method in
src/main/scala-3instead ofapplyorasyncoverloads but I can’t think of good method name.WDYT?
I have added some context function methods in scalikejdbc because there is similar use case