feature request: add Scala 3 context function methods to Action · Issue #13595 · playframework/playframework · GitHub
Skip to content

feature request: add Scala 3 context function methods to Action #13595

Open

Description

@xuwei-k

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

Activity

  1. PromanSEW commented on Oct 5, 2025

    @PromanSEW
    Contributor

    handle?

  2. xuwei-k commented on Nov 20, 2025

    @xuwei-k
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions