Using Implicit Conversions
Let’s create a practical example of implicit conversions using string interpolators. Scala has some nice built-in string interpolators—see String Interpolation—but you can also create your own custom interpolators quite easily by using the concepts we’ve seen in this chapter. We’ll create a custom interpolator that will mask out select values from the processed string. To show that the interpolation can return something other than String—just about any object—we’ll return a StringBuilder as the result of processing the string. But first let’s revisit string interpolation to explore some concepts we need for the implementation.
When Scala sees the form
interpolatorName"text1 $expr1 text2 $expr2"
the compiler turns ...