This does not work because you are using ->which is the operator (inline):
implicit final class ArrowAssoc[A](self : A) extends scala.AnyVal {
@scala.inline
def ->[B](y : B) : scala.Tuple2[A, B] = { /* compiled code */ }
def →[B](y : B) : scala.Tuple2[A, B] = { /* compiled code */ }
}
You can see that at the time of the evaluation, the BA is already “fixed”. Say you can (implicitly) convert the right side of a tuple using an operator ->:
implicit def stringToInt(str: String): Int = 10
implicit def intToStr(str: Int): String = "a"
val a: Map[Int, Int] = Map(10 -> "asd")
val b: Map[Int, Int] = Map("asd" -> 20)
val c: Map[String, String] = Map("asd" -> 20)
val d: Map[String, String] = Map(10 -> "asd")
Because of the compiler’s complexity associated with using the operator ->, @Jorg's solution works in one direction, but not in the other:
implicit def tupleIntifier(t: (String, Int)) = (10, 10)
implicit def tupleIntifier2(t: (Int, String)) = (10, 10)
val a: Map[Int, Int] = Map("asd" -> 20)
val b: Map[Int, Int] = Map(10 -> "asd")
, -> (key, value), :
val a: Map[Int, Int] = Map((10, "asd"))
val b: Map[Int, Int] = Map(("asd", 20))
implicit def stringToInt(str: String): Int = 15
println(a)
println(b)