Recursion

scala

Recursion v/s Loops in Scala

Reading Time: 3 minutes Loops need mutation, As it keeps changing the value of the variable, Scala hates mutation. Why? What is Mutation? A mutation is changing an object, variable and is one of the common side effects. Now the question arises why does scala hate mutation? Mutation might result in ambiguity, unanticipated errors, and a difficult time debugging the problem. Mutation makes it more difficult to decipher code. Continue Reading

Recursion and Tail Recursion in Scala

Reading Time: 4 minutes Introduction: Recursion is quite common in the programming world. If you don’t know recursion, it means, solving a problem by breaking it into smaller sub-problems until you solve it trivially. You can easily spot recursion if you see a method calling itself with a smaller subset of input. Recursion and immutability are corner zone of functional programming. As we have seen earlier, while using loops, Continue Reading

RECURSION / TAIL RECURSION IN SCALA

Reading Time: 3 minutes Recursion Recursion is a function which calls itself over and over again until an exit condition is met. It breaks down a large problem into a smaller problem, solves the smaller parts, and combines them to produce a solution. Recursion could be applied to many common problems, which can be solved using loops, for and while. Why Recursion? 1. The code is simpler and shorter Continue Reading