Last active
August 29, 2015 14:17
-
-
Save juanpavergara/20d097bab162b56d21e3 to your computer and use it in GitHub Desktop.
Si hay dos implicit conversion para un mismo tipo el compilador genera un error indicando que las conversiones son ambiguas.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
El error que arroja el compilador es: | |
type mismatch; found : List[String] required: List[(Option[String], String)] Note that implicit conversions are not applicable because they are ambiguous: both method List2Tuple in object StringImplicits of type (lista: List[String])List[(None.type, String)] and method List2Tuple2 in object StringImplicits2 of type (lista: List[String])List[(Some[String], String)] are possible conversion functions from List[String] to List[(Option[String], String)] Main.scala /scala_school/src/scala_school line 27 Scala Problem | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scala_school | |
object StringImplicits { | |
implicit def String2Tuple(value : String) = (None,value) | |
implicit def List2Tuple(lista: List[String]) = lista.map(String2Tuple) | |
} | |
object StringImplicits2{ | |
implicit def List2Tuple2(lista: List[String]) = lista.map((Some("_SOME_"),_)) | |
} | |
object Complex { | |
def main(args : Array[String]) : Unit = { | |
val lista = List("A", "B", "C", "D") | |
import StringImplicits._ | |
import StringImplicits2._ | |
val nuevaLista1: List[Tuple2[Option[String], String]] = lista | |
println(nuevaLista1) | |
val nuevaLista2 = lista.map((None,_)) | |
println(nuevaLista2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment