I try to write a method which should use a variable from the surrounding scope. The problem is that I cannot access the part of the code where the variable is defined. Something like this:
object Example extends App {
val myvar = 1.0 // cannot change that code
def myMethod()(implicit value:Double) = {
print(value)
}
myMethod()
}
This fails because myMethod
cannot find a suitable implicit for value
.
is there a way to "mark" value
as implicit after it has been defined, other than defining a new implicit variable pointing to value
?
Background: We use Spark-Notebook where the SparkContext
(named sc
) is created automatically. As sc
is a commonly known name for this variable in the community, we would prefer not to introduce another variable name.
implicit val myvarAgain = myvar
? – MoldingmyMethod()(myvar)
– Uncounted