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 % dmodBy2: (n: Int)(d: Int)Intscala> 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 `Int`

parameter, `n`

. It returns another function, which takes yet another `Int`

parameter, `d`

. This function finally returns the result, which is `Int`

. Well, here is the diagrammatic ...

Start Free Trial

No credit card required