Summary
In this chapter, we have taken a look at what first-class functions are and what type of use cases they open up to us as Go developers. We have taken a look at the equivalence between functions and objects, such as how they can be instantiated, passed around as parameters, stored inside other data structures, and returned from other functions.
We have also learned how type aliases can be used to create more readable code and to provide clearer error messages. We’ve seen how these can be applied to both functions as well as regular data types for structs and primitives.
In the examples, we have seen how we can create a readable function dispatcher, as well as how we can leverage first-class functions to create mocks of functions. In the next chapter, we will use what we have learned in this chapter to build higher-order functions.