Implicit Classes, Scala.
implicit class IntOps(val x: Int) extends AnyVal { def square: Int = x * x } In this case, the implicit class extends AnyVal, so it is optimized for use as a value type. We can use this implicit class like this: scala> 5.square res0: Int = 25 Now, let’s say we want to add a similar method to the