Treating Functions as First-Class Citizens
As we established in the previous chapter, the core part of our functional programs will be functions. In this chapter, we are going to cover exactly why functions are powerful in languages that treat them as first-class citizens. Go has functions as first-class citizens out of the box, meaning we get this functionality by default. More and more languages are choosing this approach. In this chapter, we are going to see how this will allow us to create interesting constructs, which will improve the readability and test ability of our code.
Concretely, we are going to cover the following topics:
- Benefits of first-class functions
- Defining types for functions
- Using functions like objects
- Anonymous functions versus named functions
- Storing functions in data types or structs
- Creating a function dispatcher using all the previous