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
791 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

If you want to know more about Apache Spark Scala, It's highly recommended to go for the Spark Training today.

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

edited Jun 1, 2023 by Srinath

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 6, 2019 in Apache Spark by Gitika
• 65,910 points
1,695 views
0 votes
1 answer

How to use uniform list in Scala?

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

answered Aug 1, 2019 in Apache Spark by Gitika
• 65,910 points
1,257 views
+2 votes
14 answers

How to create new column with function in Spark Dataframe?

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

answered Apr 5, 2019 in Apache Spark by anonymous

edited Apr 5, 2019 by Omkar 87,596 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

edited Nov 19, 2021 by Sarfaraz 8,359 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
10,620 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
2,216 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
104,982 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
684 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,910 points
514 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP