There is another way we can write the method, where each parameter is enclosed in parenthesis. For example, the
modBy2 method can also be written as follows:
scala> def modBy2(n: Int)(d: Int) = n % d modBy2: (n: Int)(d: Int)Int scala> modBy2(10)(3) res0: Int = 1
This form is called currying. Currying allows us to turn a function that expects two arguments into a function that expects only one.
By applying currying to
modBy2, we get back another function:
scala> modBy2 _ res3: Int => (Int => Int) = <function1>
This is a function that takes in an
n. It returns another function, which takes yet another
d. This function finally returns the result, which is
Int. Well, here is the diagrammatic ...