Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:41:00+00:00 2026-06-17T05:41:00+00:00

While reading Play! Framework documentation, I came across this snippet: def index = Action

  • 0

While reading Play! Framework documentation, I came across this snippet:

def index = Action { implicit request =>
  session.get("connected").map { user =>
    Ok("Hello " + user)
  }.getOrElse {
    Unauthorized("Oops, you are not connected")
  }
}

Documentation explains implicit there:

Alternatively you can retrieve the Session implicitly from a request

Besides, I read this post: Literal with Implicit and it seems logically that function cannot have implicit parameter.

If I well figured out, this is because a function, contrary to method has always a contract (interface).

Indeed, for instance, Function1[Int, Function1[Int, Int]] has as a return type’s first parameter an Int, and thus prevents us to annotate this one as implicit. This would lead to a confusion about its high-level return type: () => Int or Int => Int …

Therefore, what the previous snippet code behaves with implicit since first Action‘s required parameter is a literal function.

I guess the reason allowing compiler to accept this code is the multiple signatures of Action.apply() method:

  • def apply(block: Request[AnyContent] => Result): Action[AnyContent]
  • def apply(block: => Result): Action[AnyContent] (redirecting to the first one)

Since the second doesn’t need some parameter, is this one selected in presence of a literal function’s implicit parameter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:41:01+00:00Added an answer on June 17, 2026 at 5:41 am

    Consider the following code:

    class MyImplicitClass(val session: Int)
    object Tester {
      def apply(fun: MyImplicitClass => Int): Int = ???
      def apply(fun: => Int): Int = ???
    }
    Tester { implicit myImplicitClass => session * 20}
    

    If this function:

    def session(implicit myImplicitClass: MyImplicitClass): Int = myImplicitClass.session
    

    is in scope, then the first code snippet will compile, because clearly the implicit parameter myImplicitClass will be passed to the function session in order to access the field myImplicitClass.session, allowing you to omit the field access. This is exactly the trick the Play! Framework is using, check Controller to find the session function.

    As a side note, the above closure is not stating that it takes an implicit parameter, it’s a language feature to avoid having to do the following:

    Tester { myImplicitClass => 
      implicit val x = myImplicitClass
      session * 20
    }
    

    when one wants to use a closure parameter as an implicit value in the body of the closure. Also note that as of Scala 2.9, you are limited to closures with exactly 1 parameter for this trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reading about bitmap processing in C++ I came across this block of code
While reading SQL Server documentation I came across the following statement: EXEC sp_addlinkedserver @server=N'S1_instance1',
while reading someone's code I came across this: data = [data.a, data.b, data.c, ...
While reading on Thread Safety I came across this issue. If I'm correct method
While reading proggit today, I came upon this comment in a post about how
While reading Learning Perl , I came across a problem about regular expressions. In
While reading Python scripting for computational science I came across the following text in
While reading on Decorator pattern, came across something that needed to be clarified. In
While doing some reading, I came across the terms Intermediate Language and 3AC. IL,
While reading Bruce Eckel i came across the following example: #include <cstdio> #include <cstdlib>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.