Scope and benefits of implicit parameter request in scala action action?

I can understand how to use implicit parameters, but I doubt how necessary this is for the scala playback actions ... in the playback documentation:

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: The implicit keyword before a parameter in an anonymous function in Scala

it seems that using the implicit parameter here is just “syntactic sugar” for

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

my question is:

1) is the scope from the implicit parameter, only the scope of my lambda is not there? ... 2) Am I ignoring something? ...

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

it seems that using the implicit parameter in this case is "excessive", 3) What would the code look like without using the implicit parameter, and which template do I avoid using it?

I am rewriting this code https://stackoverflow.com/a/2129608/ without implicit parameters and definitions, and the code was much more readable and understandable (less implicit: D) ​​... I know useful cases when implicit parameters are really useful (example : akka api), but I can’t understand how useful the template is and why it should be used ...

thanks!

+4
source share
1 answer

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

2) Sorry, I do not understand this question

In general, you should use implicits sparingly. We believe that using an implicit query to go through is reasonable in this particular context.

+2
source

Source: https://habr.com/ru/post/1492833/


All Articles