I now pretty like the implicit class

when doing data cleaning, adding the customized func is pretty needed.
such as the UDF in spark.
So, I wrote a implicit class and add all my wanted func into it, such as:

scala> implicit class Myclean(i:Int) {
     |   def clean1 = {}
     |   def clean2 = {}
     |   ...
     | }
class Myclean

The next time I want to wash the data with one of the methods by just calling:

number.cleanX

It’s so convenient.
May I ask too many implicit methods will decrease the compilation speed of scala?

Thanks

It’s so convenient.

Yes they are pretty neat! And in Scala 3 they are even more convenient:

https://docs.scala-lang.org/scala3/reference/contextual/extension-methods.html

too many implicit methods will decrease the compilation speed of scala?

My experience is that using implicit classes for simple extension methods as in your example does not result in exceptionally slow compilation (it is rather other usages of implicits that can make compilation times high if the code base is large).

You can always investigate this in your setting by comparing to a simple object MyUtils that has “normal” methods, like in MyUtils.cleanX(number) and see if compile times are similar.

3 Likes