What is function currying in Scala?

0 votes
Can anyone explain with an example how currying function in Scala used?
Jul 26 in Apache Spark by Lima
28 views

1 answer to this question.

0 votes

Hi,

With Scala Currying, we can take a function that takes multiple arguments and turns it into a series of functions that take single arguments each. These come in handy working with higher-order functions. With this, we can also fill in only the arguments we have yet.

scala> def mul(a:Int,b:Int)=a*b

mul: (a: Int, b: Int)Int

scala> mul(3,4)

The output will be:

Int = 12

There is another way to do this mention below:

scala> def mul(a:Int)(b:Int)=a*b

mul: (a: Int)(b: Int)Int

scala> val mid=mul(3)(_)

mid: Int => Int = $$Lambda$1540/90644757@43fe3f7

scala> mid(4

The output will be same:

Int =12

answered Jul 26 by Gitika
• 25,340 points

Related Questions In Apache Spark

0 votes
1 answer

What is the advantage of having immutability in design for Scala programming language?

Hi, Scala uses immutability by default in most ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,340 points
42 views
0 votes
1 answer

What is ofDim in Scala?

Hey, ofDim() is a method in Scala that ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,340 points
60 views
0 votes
1 answer

What is exception propagation in Scala?

Hi, When a function experiences an exception, it ...READ MORE

answered Jul 25 in Apache Spark by Gitika
• 25,340 points
29 views
0 votes
1 answer

What is BitSet in Scala?

Hey, A BitSet is a set of non-negative ...READ MORE

answered Jul 25 in Apache Spark by Gitika
• 25,340 points
35 views
0 votes
1 answer
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,710 points
3,299 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,710 points
390 views
0 votes
10 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
16,236 views
0 votes
1 answer

What is recursion in Scala function? How does it works?

Hey, A Scala function involves recursion when it ...READ MORE

answered Jul 25 in Apache Spark by Gitika
• 25,340 points
24 views
0 votes
1 answer

What is “Unit” and “()” in Scala?

Hey, Unit is a subtype of scala.anyval and ...READ MORE

answered Jul 24 in Apache Spark by Gitika
• 25,340 points
40 views