When should you make methods with an implicit argument in Scala?

I have created codes using the play framework in scala that look like this:

object Application extends Controller {
  def hoge = Action( implicit request =>
    val username = MyCookie.getName.get
    Ok("hello " + username)
  }
}

object MyCookie {
  def getName( implicit request: RequestHeader ) = {
    request.cookies.get("name").map(_.value)
  }
}

I got a code review from my colleague. He said that this code is not readable due to an implicit parameter. I could not answer his opinion. So could you tell me what is the best way to use implicit parameters? When should you use implicit parameters?

+5
source share
1 answer

, "" -, ; -, , .

, scala.concurrent.Future, ExecutionContext. , ExecutionContext ; , . , .

CanBuildFrom . -; , , , , Vector[Option[String]] HashSet[Char], , .

: , , . , , , , , , . , , :

Action{ req => val name = MyCookie.getName(req).get; Ok("hello "+name) }
+11

All Articles