0 votes
in Scala Constructs by
Explain the function Currying in Scala.

1 Answer

0 votes
by

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. 

Related questions

0 votes
asked Sep 10, 2022 in Scala Constructs by Robin
0 votes
0 votes
asked Sep 12, 2022 in Scala Constructs by Robin
...