Functionals
Malte Grosser, Henning Bumann, Hadley Wickham · 2021
In chapter 9 we’ll learn about functionals. A functional is a function that takes a function as an input and returns a vector as output. A common use of functionals is as an alternative to for loops. As loops do not convey what should be done with the results, it&s;s better to use a functional. Each functional is tailored for a specific task, so when you recognise the functional you immediately know why it&s;s being used. “My first functional: map()” introduces your first functional: purrr::map(). “Map variants” teaches you about 18 (!!) important variants of purrr::map(). Fortunately, their orthogonal design makes them easy to learn, remember, and master. “Predicate functionals” teaches you about predicates: functions that return a single TRUE or FALSE, and the family of functionals that use them to solve common problems. “Base functionals” reviews some functionals in base R that are not members of the map, reduce, or predicate families.