Producing Functions – Higher-Order Functions
In Chapter 5, Programming Declaratively, we worked with some declarative code so that we could gain understandability and more compact, shorter code. In this chapter, we will go further toward higher-order functions (HOFs) and develop our own. We can roughly classify the results that we are going to get into three groups:
- Wrapped functions: These keep their original functionality while adding some kind of new feature. In this group, we can consider logging (adding log production capacity to any function), timing (producing time and performance data for a given function), and memoization of functions and promises (caching results to avoid future rework).
- Altered functions: These differ in some key points from their original versions. Here, we can include the
once()
function (we covered this in Chapter 2, Thinking Functionally), which changes the original function so that it only runs once; functions such asnot()
orinvert...