Hey,
A Scala function involves recursion when it makes a call to itself. Let’s take an example:
scala> def factorial(n:Int):Int={
| if(n==1)
| {
| return 1
| }
| n*factorial(n-1)
| }
factorial: (n: Int)Int
scala> factorial(6)
res0: Int = 720
scala> factorial(1)
res1: Int = 1
scala> factorial(4)
res2: Int = 24
scala> factorial(10)
res4: Int = 3628800
This Scala function correctly calculates the factorial of an integer one or greater.
If you want to know more about Apache Spark Scala, It's highly recommended to go for the Apache Spark Certification today.