hands-on lab

Mastering Pattern Matching in Scala

Difficulty: Advanced
Duration: Up to 45 minutes
Students: 69
Rating: 5/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.

Description

If you are working with the functional programming paradigm and need to retrieve a specific expression depending on the value or type of an expression, you should consider using pattern matching. Pattern matching lets you check for a specific value or type of an expression, leveraging constructors and types, constants, and wildcards. You should use pattern matching and avoid nested if/else or custom methods to check conditions, to have a more readable and compact result.

Pattern matching can be applied to all data structures such as List and Map, and both to case native and custom classes (you just need to insert case in the class definition).

In this lab, you will understand how to work with pattern matching, and you will implement it with real-world cases.

Learning Objectives

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

  • Understand how pattern matching works
  • Implement pattern matching to solve real world scenarios

Intended Audience

This lab is intended for:

  • Software engineers leveraging the functional programming paradigm that needs to implement a compact solution to match expressions
  • Data engineers working with data structures that need to get expressions depending on the form of the data structure

Prerequisites

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

Updates

April 20th, 2023 - Updated theia to enable autosave

Covered topics

Lab steps

Understanding the Pattern Matching
Connecting to the Scala Web IDE
Working With Pattern Matching in Scala