For example, how can I write an expression where the following is implicitly applied:
implicit def intsToString(x: Int, y: Int) = "test"
val s: String = ... //?
Thanks
For example, how can I write an expression where the following is implicitly applied:
implicit def intsToString(x: Int, y: Int) = "test"
val s: String = ... //?
Thanks
Implicit functions of one argument are used to automatically convert values to an expected type. These are known as Implicit Views. With two arguments, it doesn't work or make sense.
You could apply an implicit view to a
TupleN
:You can also mark the final parameter list of any function as implicit.
Or, combining these two usages of
implicit
:However it's not really useful in this case.
UPDATE
To elaborate on Martin's comment, this is possible.
Jason's answer misses out one very important case: an implicit function with multiple arguments where all but the first are implicit ... this requires two parameter lists, but that doesn't seem to be out of scope given the way the question was expressed.
Here's an example of an implicit conversion which takes two arguments,
Sample REPL session,