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
75 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
• 25,460 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
• 25,460 points
88 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
• 25,460 points
157 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 33,858 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
• 10,840 points
1,850 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,840 points
3,915 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,840 points
539 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
20,825 views
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
• 25,460 points
59 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
• 25,460 points
46 views