Mastering Pattern Matching in Scala
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:
- Understanding Basic Scala Elements for Functional Programming
- Starting using Recursion with Scala
- Creating and Handling Classes and Hierarchies in Scala
- Introducing Generics for Classes and Functions in Scala
- Leveraging Common Scala Immutable Data Structures
- Writing and Using Higher-Order and Anonymous Functions in Scala
- Integrating Common Higher-Order Functions with the For-Expressions in Scala
Updates
April 20th, 2023 - Updated theia to enable autosave