Summary
In this chapter, we covered three things: closures, partial application, and currying. By using closures, we learned how we can share the context of variables between outer and inner functions. This allowed us to build flexible applications, such as the final “constructor” example. Next, we learned how to use a partially applied function to fix certain arguments to an n-ary function. This shows us how we can create default configurations for functions, such as how we created a HavaneseSpawner
option in our example. Finally, we learned about function currying and how this relates to partial application. We showed how we can extend our partial application example by transforming each function into unary function calls. All three techniques have allowed us to create more composable and reusable functions.
Up until now, we have not been concerned with function purity and have played a bit fast and loose with the state of our system. In the next chapter, we are...