partial function

This is a page from my book, Functional Programming, Simplified

Using Scala Methods As If They Were Functions (Eta Expansion)

“The owls are not what they seem.”

From the television series, Twin Peaks

Goals

Have you noticed that the Scaladoc for the List class map method clearly shows that it takes a function?

But despite that, you can somehow pass it a method, and it still works, as shown in this code:

How to create and use partial functions in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 9.8, “How to create and use partial functions in Scala.”

Problem

You want to define a function that will only work for a subset of possible input values, or you want to define a series of functions that only work for a subset of input values, and combine those functions to completely solve a problem.