September 2018
Intermediate to advanced
398 pages
9h 43m
English
In a function definition, the last parameter list can be marked as implicit. Such a function can then be invoked without passing the corresponding arguments. When you omit the implicit arguments, the Scala compiler will try to find implicit values of the same type in the current scope and will use them as arguments to the function.
Here is an illustration of this mechanism that you can type into a Scala worksheet:
case class AppContext(message: String)implicit val myAppCtx: AppContext = AppContext("implicit world")def greeting(prefix: String)(implicit appCtx: AppContext): String = prefix + appCtx.messagegreeting("hello ")// res0: String = hello implicit world
We first declare a new AppContext class and assign a new instance ...
Read now
Unlock full access