Randomize Randomize - 1 year ago 114
Scala Question

Scala: implicitly to implicit class


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

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

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

Answer Source

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)?