As its name indicates, the Scala keyword implicit can be used to implicitly add some extra code to the compiler. For instance, an implicit parameter in a function definition allows you to omit this parameter when you call the function. As a result, you do not have to pass this parameter explicitly.
There are different kinds of implicit in Scala that we will cover in this section:
- An implicit parameter is declared in a function definition
- An implicit value is passed as an argument to a function that has an implicit parameter
- An implicit conversion converts one type to another type
This is an extremely powerful feature that can feel a bit like magic sometimes. In this section, we will see how it can help writing more concise code and also how to use it to validate some constraints at compile time. In the next chapter, we will use them to define another...