This is the correct list to ask *scala* questions, which you have. Not sure I can help much with Play details, but here's the Scala bits you need.
In Scala, any object that has an 'apply' method can be treated as if it were a function. e.g.
object foo {
def apply(x: Int) = prinltn(x)
}
foo(1) // Prints 1
In play, Action + Ok are both top-level objects (singletons if you will). You want to look at the documentation for the *object* not the trait. (Click the 'O' icon beside the 'T').
Now, you can pass "expressions" as arguments to a method, the same as anything else. For example, in OK, I'm pretty user it takes a "by-name" parameter expression:
object Ok {
def apply[A](k: => A): Result = ...
}
So when you write:
Ok("Got request [" + request + "]")
the compiler rewrites it as:
Ok.apply[String]("Got request [" + request + "]")
*technically, it gets rewritten into something a bit more foreign, but hopefully you get the idea.
Now for Action, it probably takes a *function* as its argument. So you see something like this:
object Action {
def apply(function: Request => Response): SomeReturnValue = ...
}
In scala, we can invoke Action with a function block:
Action { request => ..... }
This is rewritten as:
Action.apply({ request => ... })
You may be wondering what the implicit keyword is doing. It's a shorthand convenince to make the argument to a function available on the implciit scope within the function. In other words:
Action apply { implicit request => ... }
is the same as:
Action apply { request =>
implicit val _some_random_name_ = request
...
}
Hope that Helps!
- Josh