hands-on lab

Start using Recursion with Scala

Intermediate
Up to 45m
141
3.6/5
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.
Lab description

The functional paradigm is a strong and synthetic approach to write software. If you are confident with OOP (Object Oriented Programming), it could be difficult to switch to the functional one because most of the structures you are confident with can't be used and are not contemplated. One of them is iteration. When you code with the functional paradigm, you won't use loops described by while, do-while, and for.

The substitute of the iteration is the recursion. This concept is applied to the functions you write. A recursive function is a function that contains a call to itself in its body. Recursion is a powerful method to write compositional code but it's also dangerous to use: you could write infinite loops. Also, if the recursion is not the last operation made in the code, you could reserve too much space in memory. For that last problem, Scala allows you to leverage the tail-recursion.

In this lab, you will understand the principles of recursion and you will use Scala to write recursive functions and tail-recursive functions.

Learning Objectives

Upon completion of this beginner level lab, you will be able to:

  • Understand the basic concepts of recursion
  • Write recursive functions and tail-recursive functions in Scala

Intended Audience

This lab is intended for:

  • Software engineers who need to move to the functional paradigm with Scala
  • Developers that want to fully understand how to leverage recursion in Scala

Prerequisites

To get the most out of this lab, you should have basic knowledge of Scala. To achieve this, we suggest taking the following lab:

Updates

April 20th, 2023 - Updated theia to enable autosave

About the author
Students
40,448
Labs
106
Courses
2
Learning paths
10

Stefano studies Computer Science and is passionate about technology. He loves working with Cloud services and learning all the best practices for them. Google Cloud Platform and Amazon Web Services are the cloud providers he prefers. He is a Google Cloud Certified Associate Cloud Engineer. Node.js is the programming language he always uses to code. When he's not involved in studying or working, Stefano loves riding his motorbike and exploring new places.

Covered topics
Lab steps
Understanding Scala Recursion Principles
Connecting to the Scala Web IDE
Working With Recursion in Scala