Play / scala, implicit request => what does it mean?

Most of the gaming environment I see a block of code

// Returns a tasks or an 'ItemNotFound' error
def info(id: Long) = SecuredApiAction { implicit request =>
  maybeItem(Task.findById(id))
}

yes, my understanding defines a method info(id: Long)and in the scala doc to create a function in scala, the syntax is as follows:

def functionName ([list of parameters]) : [return type] = {
   function body
   return [expr]
}

Can you tell me what it means implicit request =>and SecuredApiActionput before{

+4
source share
1 answer

play.api.mvc.Actionhas helper methods for processing queries and returning results. One, if it applyoverloads, takes a parameterplay.api.mvc.Request :

def apply(request: Request[A]): Future[Result]

implicit, , . Play Framework:

, API-, .

, , :

object X {
  def m(): Unit = {
    implicit val myInt = 42
    y()
  }

  def y()(implicit i: Int): Unit = {
    println(i)
  }
}

implicit, y() myInt .

scala> :pa
// Entering paste mode (ctrl-D to finish)

object X {
  def m(): Unit = {
    implicit val myInt = 42
    y()
  }

  def y()(implicit i: Int): Unit = {
    println(i)
  }
}

// Exiting paste mode, now interpreting.

defined object X

scala> X.m()
42
+3

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


All Articles