hands-on lab

Writing and Using Higher-Order and Anonymous Functions in Scala

Intermediate
Up to 45m
67
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 use the functional programming paradigm, the function is the core component you need to focus on and use. It can be used as a value, so you can set a value for it (defining the body of a function), and you can use it as a function's argument, and also as a return value. A function that takes a function as an argument or returns it as a value is called a higher-order function.

Most of the time, the functions you need to pass as an argument to another function are not shared and used by other components. In this situation, creating the functions could pollute the environment namespace (you have a lot of functions that are only used by a single entity or a single time). To avoid this scenario, you can pass the body of a function to another function without defining the function you need to pass as an argument; you simply pass the value. This kind of function is called anonymous function (you could hear about it also as a lambda function). That's because it doesn't have a formal definition, and can't be referred to.

In this lab, you will start using higher-order functions and anonymous, with a focus on the three most used higher-order functions in functional programming: map, filter, and reduce.

Learning Objectives

Upon completion of this beginner level lab, you will be able to:

  • Understand higher-order functions and anonymous functions
  • Start using higher-order functions and anonymous functions to better solve problems

Intended Audience

This lab is intended for:

  • Software engineers focusing on the functional programming paradigm
  • Data engineers need to follow a clear way to handle and manipulate data

Prerequisites

To get the most out of this lab, you should have basic knowledge of Scala. To achieve this, the following labs are suggested:

Updates

April 20th, 2023 - Updated theia to enable autosave

About the author
Students
40,448
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
Connecting to the Scala Web IDE
Working with Higher-Order and Anonymous Functions