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.
Upon completion of this beginner level lab, you will be able to:
This lab is intended for:
To get the most out of this lab, you should have basic knowledge of Scala. To achieve this, we suggest taking the following labs:
April 20th, 2023 - Updated theia to enable autosave
November 18th, 2022 - Updated the instructions and screenshots to reflect the latest UI
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.