Randomize Randomize - 18 days ago 6
Scala Question

Scala: implicitly to implicit class

Given:

implicit class Foo(val i: Int) {
def addValue(v: Int): Int = i + v
}


is it possible apply to it any
implicitly
?
I get an error here:

<console>:14: error: could not find implicit value for parameter e: Foo
implicitly[Foo]

Answer

An implicit class Foo(val i: Int) means that there is an implicit conversion from Int to Foo. So implicitly[Int => Foo] should work.

If you could summon a Foo with implicitly[Foo], which Foo would you expect to get? A Foo(0)? A Foo(1)? A Foo(2)?