# Currying Function in Scala Learning Scala involves learning lots of new concepts and syntax. In this blog post you will learn one of the important concept know as Currying function in scala.

# Definition

Definition : Currying is the technique of transforming a function with multiple arguments into a function with just one argument.

Let us understand with an example program

```def multiply(num1:Int,num2:Int):Int={
num1+num2;
}```

In the above example we have a function by name “multiply” which takes two arguments i.e num1 and num2

Since scala supports curried functions, we can turn into curried version by simply separating out the arguments as shown below.

## Short hand Curried function

```def multiply(num1:Int) (num2:Int):Int={
num1+num2
}```

## Long hand Curried function

The above curried function is short hand for the code shown below:

```def multiply(x: Int): (Int => Int) = {
(y: Int) => {
x + y
}
}```

Let me explain the above code, If you observe the above code the return type of a function is another function i.e after “:” what you see is a return type hence the function returns (num2:Int):Int

Let us invoke the function

```scala> val functionOutput = multiply(2)

```

Output

`functionOutput: Int => Int = <function1>`

Invoking on a return function

`scala> val output = functionOutput(3)`

Output:

`output: Int = 5`

## Summary:

1. Currying is the technique of transforming a function with multiple arguments into a function with just one argument.
2. The single argument is the value of the first argument from the original function.
3. The function returns another single argument function. This in turn would take the second original argument and itself return another single argument function. This chaining continues over the number of arguments of the original. The last in the chain will have access to all of the arguments and so can do whatever it needs to do. 