Higher-Order Functions
The other aspect of functional style is working with higher-order functions—this is the facility that treats functions as first-class citizens. It lets us pass functions to functions, create functions within functions, and return functions from functions. This in turn allows for functional composition, and a virtue of Scala is that we can design using both functional composition and object composition, as we desire or as appropriate.
Let’s explore Scala’s approach to functional programming with some examples. We’ll start with some small examples that just manipulate numbers so we can easily grasp how to use higher-order functions in Scala. And then we’ll look at a practical example where we apply the concepts we’ve learned. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access