hands-on lab

Integrating Common Higher-Order Functions with the For-Expressions in Scala

Advanced
45m
66
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.
Lab 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:

Updates

April 20th, 2023 - Updated theia to enable autosave

November 18th, 2022 - Updated the instructions and screenshots to reflect the latest UI

About the author
Students
40,024
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 For-Expressions Components
Connecting to the Scala Web IDE
Working With For-Expressions in Scala