Functions are Data

Let’s learn how functions can be used as data.

Using functions as data

The generators in the previous example illustrate an underappreciated aspect of functional programming. Namely, functions are just another datatype.

Anywhere we can pass some data as an argument, we can pass a function instead. The BEAM even serializes functions, just like other types.

For example, when we learn to think of functions as data, it should radically change how we approach problems. Let’s take another look at /lib/mastery/core/question.ex:

Get hands-on with 1200+ tech skills courses.