20 Higher order functions

After reading this lesson, you will be able to

  • Define functions that have functions as parameters
  • Implement functions that return functions
  • Build powerful abstractions that remove code duplication

Functions are first-class citizens in Scala: you can use them as parameters or return them as the result of some computation. Higher order functions are functions that accept other functions as parameters, return functions, or both. Their use allows you to create powerful abstractions that reduce duplication and increase the reusability of your code. In the capstone, you’ll use higher order functions to extract information on the winner of the game “Paper, Rock, Scissors, Lizard, Spock!”

Consider this

Suppose you want ...

Get Get Programming with Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.