How 'Scala Higher Order function' works in Scala?

0 votes
Can anyone provide an example on how Scala Higher Order function works in Scala?
Jul 30, 2019 in Apache Spark by Amrita
56 views

1 answer to this question.

0 votes

Hey,

Scala allows the definition of a higher-order function. These are functions that take other functions as parameters, or whose result is a function. In the following example, apply () function takes another function 'f' and a value 'v' and applies the function to v.

object Test {
 def main(args: Array[String]) {
 println( apply( layout, 10) )
 }
 def apply(f: Int => String, v: Int) = f(v)
 def layout[A](x: A) = "[" + x.toString() + "]"

When the above code is compiled and executed, it produces the following result 

         C:/>scalac Test.scala
          C:/>scala Test
          [10]
          C:/>

answered Jul 30, 2019 by Gitika
• 26,110 points

Related Questions In Apache Spark

0 votes
1 answer

How to execute a function in apache-scala?

Hi, Here is a simple example of how ...READ MORE

answered Jul 1, 2019 in Apache Spark by Gitika
• 26,110 points
70 views
0 votes
1 answer

How can we iterate any function using "foreach" function in scala?

Hi, Yes, "foreach" function you use because it will ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 26,110 points
352 views
0 votes
1 answer

How to use nested function in Scala?

Hey, With Scala, we can define a Scala ...READ MORE

answered Jul 26, 2019 in Apache Spark by Gitika
• 26,110 points
82 views
0 votes
11 answers

How to create new column with function in Spark Dataframe?

val coder: (Int => String) = v ...READ MORE

answered Apr 4, 2019 in Apache Spark by anonymous

edited Apr 5, 2019 by Omkar 41,628 views
+1 vote
1 answer
+1 vote
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,870 points
4,500 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,870 points
640 views
+1 vote
11 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
25,310 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, 2019 in Apache Spark by Gitika
• 26,110 points
44 views
0 votes
1 answer

How does Closure function works in Scala?

Hi, A closure in Scala is a function ...READ MORE

answered Jul 26, 2019 in Apache Spark by Gitika
• 26,110 points
46 views