Function Type in Scala PRO

Scala allows us to define variables, function parameters and function returned values with a type that is a function. We can even specify the exact signature of that function. import annotation.tailrec object Program { def main(args: Array[String]):Unit = { var func:(Int,Int)=>Int = sum; println(func(4,3)) func = multiply println(func(4,3)) } def sum(a:Int,b:Int):Int = a+b def multiply(a:Int,b:Int):Int […]

Tail Recursive Function in Scala PRO

If the last action a function performs is calling to itself then it is a tail recursive function. When a tail recursive function is executed the computer doesn’t need to keep the memory stack frames. It can use one frame only. Using the @tailrec annotation we can instruct the computer to use one frame only […]

Multiple Lines Expressions in Scala PRO

When having an expression that spans over more than one line the compiler might evaluate the expression while avoiding parts of the expression. We can overcome this problem in two ways. This video clip explains this issue.

Skip to content Update cookies preferences