Writing and Using Higher-Order and Anonymous Functions in Scala

Lab Steps

lock
Connecting to the Scala Web IDE
lock
Working with Higher-Order and Anonymous Functions

The hands-on lab is part of this learning path

Ready for the real environment experience?

DifficultyIntermediate
Time Limit45m
Students14
Ratings
5/5
starstarstarstarstar

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:

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