Mark existing variable as candiate for implicit method

I am trying to write a method that should use an environment variable. The problem is that I cannot access the part of the code where the variable is defined. Something like that:

object Example extends App {

  val myvar = 1.0 // cannot change that code

  def myMethod()(implicit value:Double) = {
      print(value)
  }

  myMethod()
}

This fails because it myMethodcannot find a suitable implicit for value.

is there a way to “mark” valueas implicit after it has been defined, other than defining a new implicit variable that points to value?

Reference Information. We use Spark-Notebook, where SparkContext(with a name sc) is created automatically. Since this scis a well-known name for this variable in the community, we would prefer not to enter another variable name.

+4
1

SparkContext, sc, implicit-underscore :

implicit val _: SparkContext = sc

.


,

myMethod()(myvar)

, .

+3

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


All Articles