Scala lets you create functions with multiple parameter groups, syntax is quite simple and similar to any regular function like below
//regular function
def sum(x: Int, y: Int, z: Int): Int = x+y+z
//function with multiple parameter groups
def add(x:Int)(y:Int)(z:Int): Int = x+y+z
//difference in function calls
sum(1,2,3) //calling a regular function
add(1)(2)(3) //calling a function which has multiple parameter groups
Benefits of this approach:
- They let you have both implicit and non-implicit parameters
- A parameter in one group can use a parameter from a previous group as a default value
- you will get to know the inside approach of control structures and you can even create one of your own.
we will see all these benefits with examples.
Continue reading →