Integrating Common Higher-Order Functions with the For-Expressions in Scala
Description
When you follow the functional programming paradigm, you probably need to create and handle loops. You can leverage recursion, but there is also another possible way: for-expressions. A for-expression represents a loop over a set of items, where you can make assignments, and apply filters. In for-expressions, you need to use the yield key word at the end, to let the for-expression returns values. Suppose you start from a List of five strings, and you want to capitalize them all into a new List. You can do it by using a for-expression, and you need to yield the new five capitalized strings.
For-expressions are also good candidates when it comes to the need to implement map and filter higher-order functions in a very synthetic and compact way.
In this lab, you will understand the components of for-expressions, and you will start working with them.
Learning Objectives
Upon completion of this beginner level lab, you will be able to:
- Understanding for-expressions
- Solving different problems using for-expressions
Intended Audience
This lab is intended for:
- Software engineers focused on the functional paradigm that needs to solve loops problems in a compact way
- Data engineers that need to handle and apply operations on data sets
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
Updates
April 20th, 2023 - Updated theia to enable autosave
November 18th, 2022 - Updated the instructions and screenshots to reflect the latest UI