Based on the way we use them, the Scala operators can be classified into three types:
- Infix operators
- Prefix operators
- Postfix operators
We use operators to perform some operation on operands, which is obvious, and the way we implement makes them infix, prefix, or postfix. A basic example of an infix operator is addition +:
scala> val x = 1 + 10
x: Int = 11
We have two operands (1 and 10) on which this addition operation is being performed. We've already discussed that operators are methods. It means that somehow the operation is being performed as 1.+(10), and 1 + 10 is just syntactic sugar of how we can write this. This is possible because the method + is defined for the given types. Here, in our case, the addition (+) method is defined for Int. Along with this, there are several versions of overloaded methods that support other numeric value...