4 Creating new functions from the old ones
This chapter covers
- Understanding partial function application
- Fixing function arguments to specific values with
std::bind
- Using lambdas for partial function application
- Are all functions in the world unary?
- Creating functions that operate on collections of items
Most programming paradigms tend to provide a way to increase code reusability. In the object-oriented world, we create classes we can later use in various situations. We can use them directly or combine them to implement more-complex classes. The possibility of breaking complex systems into smaller components that can be used and tested separately is a powerful one.
In the same way that OOP gives you the tools to combine and modify types, the functional programming paradigm gives you ways to easily create new functions by combining the functions we’ve already written, by upgrading specialized functions to cover more-general use cases, or, the other way around, by taking more-general functions and simplifying them to perfectly fit a specific use case.