How to use nested function in Scala?

0 votes
Can anyone provide an example regarding how nested function works in Scala?
Jul 26 in Apache Spark by Dheer
63 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 by Gitika
• 25,340 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 in Apache Spark by Gitika
• 25,340 points
66 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 in Apache Spark by Gitika
• 25,340 points
58 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 in Apache Spark by anonymous

edited Apr 5 by Omkar 24,166 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,690 points
1,371 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,690 points
3,063 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,690 points
341 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
15,042 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 in Apache Spark by Gitika
• 25,340 points
43 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 in Apache Spark by Gitika
• 25,340 points
33 views