Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list all useable implicit conversion?

Tags:

scala

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.

like image 530
John Zeng Avatar asked Sep 14 '16 06:09

John Zeng


People also ask

What is implicit type conversion in C?

Implicit Type Conversion in C. C allows us to mix basic types in an expression. We have seen a glimpse of this behavior while discussing mixed mode arithmetic in chapter Arithmetic Operators in C. In such expressions, operand of one type is converted to another type. This process is known as Type Conversion.

When should the implicit keyword be used to enable implicit conversions?

Amount cannot be converted in to Money; therefore, we need explicit casting. So as to summarize, the implicit keyword should be used to enable implicit conversions between a user-defined type and another type, if the conversion is guaranteed not to cause a loss of data.

What is an explicit conversion in JavaScript?

Performing an explicit conversion is also known as casting an expression to a given data type or object class.

What are the two types of type conversion?

There are two types of type conversion: Implicit type conversion. Explicit type conversion. In this chapter, we are discussing Implicit type conversion. This type of conversion is done by the compiler according to the following rules:


1 Answers

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]]
                 ^
like image 115
jwvh Avatar answered Sep 29 '22 18:09

jwvh