I'm implementing a plus method that should work this way:
1 plus 2 // 3 "a" plus "b" // "a and b = ab"
Here is my implementation:
object MyMath {
implicit class MyMath(a: Any) {
def plus(b: Any) = {
(a, b) match {
case (s: String, s2: String) => s"$s and $s2"
case(i: Int, i2: Int) => i + i2
}
}
}
def main(args: Array[String]) {
println(1 plus 2)
println("a" plus "b")
}
}
Should I avoid using type Any
? Is this a sign of a code smell if I use Any
too much?