Scala Things To Know Flashcards

1
Q

implicit

A

Used to tell compiler to look for a specific type -> and if that type is not found, to look for a function that will convert the found type into the desired type.

Ex. To convert a value to an int we could do the following without use of implicits:

def doubleToInt(x: Double): Int = x.toInt
val x: Int = doubleToInt(42.0)

—OR WITH IMPLICIT—

implicit def doubleToInt(d: Double) = d.toInt
val x: Int = 42.0 //auto-converts this to an Int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly