John Zeng John Zeng - 6 months ago 66
Scala Question

How can I list all useable implicit conversion?

I know that in SCALA I can convert a type to another by define some implicit function, my question is , how can I know what conversions can I use after importing tons of packages?

For example, I have a string, and than how can I know what types can it convert to ?

Edit to clarify, I wanna do it in my scala compile plugin, so I may need to call a function on a reflect.api.tree type, and then get the implicits. I am looking some method to use the implicitly[] mentioned in the answer.


In the REPL you can invoke :implicits to see all the in-scope implicits other than those available from the Predef. (Add -v to see Predef implicits as well.)

You can also invoke the implicitly[] function from anywhere in your code to test for particular implicits.

scala> implicitly[String => Seq[Char]]
res0: String => Seq[Char] = <function1>

scala> implicitly[String => Array[Char]]
<console>:12: error: No implicit view available from String => Array[Char].
       implicitly[String => Array[Char]]