Google News
logo
Scala - Interview Questions
Explain the function Currying in Scala.
In Scala, currying refers to the technique of transforming a function. There are multiple arguments passed into this function, which then forms a chain of functions that take one argument each. This type of function is widely used in multiple functional languages.

 Syntax :
 def curryfunction_name(argument1, argument2) = operation ​

Example :
object Currying
{
    def add(a: Int, b: Int) = a + b;
    def main(args: Array[String])
    {
      println(add(10, 5));
    }
} ​

Output :
15  ​

In this case, we've defined an add function that takes two arguments (a and b), and it gives us the result of adding a and b, by calling it in the main function.
Advertisement