lundi 20 avril 2015

Apply Method with Implicits Partially

Given the following method:

scala> def f(x: Int)(implicit y: Int, z: Int) = x + y + z
f: (x: Int)(implicit y: Int, implicit z: Int)Int

I can define an implicit, and then apply it.

scala> implicit val x: Int = 5
x: Int = 5

scala> f(10)
res0: Int = 20

But, evidently, I cannot only specify a single implicit argument:

scala> f(10)(y = 10)
<console>:10: error: not enough arguments for method f: 
    (implicit y: Int, implicit z: Int)Int.
Unspecified value parameter z.
              f(10)(y = 10)

Is it possible to specify an implicit argument, i.e. y, but leave z to implicit resolution?

Aucun commentaire:

Enregistrer un commentaire