Writing and Using Higher-Order and Anonymous Functions in Scala
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:
- Understanding Basic Scala Elements for Functional Programming
- Starting using Recursion with Scala
- Creating and Handling Classes and Hierarchies in Scala
- Introducing Generics for Classes and Functions in Scala
- Leveraging Common Scala Immutable Data Structures
Updates
April 20th, 2023 - Updated theia to enable autosave