Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scope and benefit of implicit parameter request in a scala play action?

I can understand how use implicit parameters but I've the doubt about how necessary is it for the scala play actions...in the play documentation appear this:

It is often useful to mark the request parameter as implicit so it can be implicitely used by other APIs that need it

now...reading this other stackoverflow answer: Implicit keyword before a parameter in anonymous function in Scala

seems than the use the implicit parameter here is only a "syntax sugar" for

 Action { request =>
   Ok("Got request [" + request + "]",request)  //with implicit request I avoid pass the request parameter...
  }

my question are:

1) is the scope from the implicit parameter only the scope from my lambda no?... 2) do I'm ignoring something about it?...

reading this other answer: When should I make methods with implicit argument in Scala?

seems than use implicit parameter in this case is "overuse" 3) How would look a code without use implicit parameter and what boilerplate I'm avoiding using it??

I rewrite this code https://stackoverflow.com/a/5015161/340451 without implicit parameter and definitions and the code was much more readable and clear (less implicit :D)...I know useful cases where implicit parameters are really helpful (example: the akka api) but I can't understand how useful is it pattern and why must be used...

thanks!

like image 774
clagccs Avatar asked Nov 03 '22 18:11

clagccs


1 Answers

1) Yes, the scope of the request is within the action block

2) Sorry, don't understand this question

In general you should use implicits sparingly. We think the use of an implicit to pass around the request is reasonable in this particular context.

like image 133
Christopher Hunt Avatar answered Nov 08 '22 06:11

Christopher Hunt