How to use nested function in Scala

0 votes
Can anyone provide an example regarding how nested function works in Scala?
Jul 26, 2019 in Apache Spark by Dheer
223 views

1 answer to this question.

0 votes

Hey,

With Scala, we can define a Scala function inside another. This is what a local function looks like:

Let's take an example:

scala> def outer(){

| println("In outer")

| def inner(){

| println("In inner")

| }

| inner()

| }

outer: ()Unit

scala> outer()

The output will be:

In outer
In inner

One other example for your clear visual here:

scala> def outer(a:Int){

| println("In outer")

| def inner(){

| println(a*3)

| }

| inner()

| }
outer: (a: Int)Unit
scala> outer(3)

The Output will be

In outer
9

answered Jul 26, 2019 by Gitika
• 65,870 points

Related Questions In Apache Spark

0 votes
1 answer

How to use yield keyword in scala and why it is used instead of println?

Hi, The yield keyword is used because the ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 65,870 points
498 views
0 votes
1 answer

How to use uniform list in Scala?

Hey, The method List.fill() creates a list and ...READ MORE

answered Jul 31, 2019 in Apache Spark by Gitika
• 65,870 points
668 views
+2 votes
14 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 67,601 views
0 votes
1 answer

How to add third party java jars for use in PySpark?

You can add external jars as arguments ...READ MORE

answered Jul 4, 2018 in Apache Spark by nitinrawat895
• 11,380 points
5,540 views
+1 vote
2 answers
+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
• 11,380 points
7,086 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
• 11,380 points
1,138 views
+2 votes
11 answers

hadoop fs -put command?

Hi, You can create one directory in HDFS ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by nitinrawat895
• 11,380 points
51,178 views
0 votes
2 answers

How to execute a function in apache-scala?

Function Definition : def test():Unit{ var a=10 var b=20 var c=a+b } calling ...READ MORE

answered Aug 5, 2020 in Apache Spark by Ramkumar Ramasamy
191 views
0 votes
1 answer

How can you use "for" statement in scala to print list from collection?

Hi, You can use for loop in scala using ...READ MORE

answered Jul 5, 2019 in Apache Spark by Gitika
• 65,870 points
133 views