0

I've always thought that Scala implicit conversions could only take one argument, and if you needed something like conversion from multiple arguments, you would use a tuple. However, I was surprised to find that Scala 2.10.3 actually accepts this (silly) definition without problem:

scala> implicit def foo(i: Int, j: Int): Int = i
foo: (i: Int, j: Int)Int

Is there any way or reason to use such a multi-argument implicit?

3
  • 1
    You could use it like this: def bar[A, B, C](a: A, b: B)(implicit f: (A, B) => C) = f(a, b), though I don't think it's useful. Commented Jan 15, 2014 at 7:43
  • 1
    For the record, amazing how @retronym covers the bases. Is there more than one retronym? Is it a retronym collective? Commented Jan 15, 2014 at 8:57
  • @som-snytt: In a manner of speaking... At least one of them is Tyler Durden Commented Jan 15, 2014 at 11:37

1 Answer 1

1

Not all implicit functions are conversions!

Any implicit function with a single argument could be used as a conversion, but that's not the only use-case for implicits.

Functions are just another type and, as such, you can specify an implicit argument as in (implicit fn: (Int, Int) => Int)

I wouldn't do this though, anything you intend to pass as an implicit should have a far more specific type that better self-documents its intended purpose.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.