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

Lab Steps

lock
Understanding For-Expressions Components
lock
Connecting to the Scala Web IDE
lock
Working With For-Expressions in Scala

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyAdvanced
Time Limit45m
Students12
Ratings
5/5
starstarstarstarstar

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:

About the Author
Students19315
Labs94
Courses2
Learning paths7

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