Partial application
Now that we understand closures, we can start thinking about partial application. The name “partial application” quite explicitly tells us what is happening – it is a function that is partially applied. This is perhaps still a bit cryptic. A partially applied function is taking a function that takes N number of arguments and “fixing” a subset of these arguments. By fixing a subset of the arguments, they become set in stone, while the other input parameters remain flexible.
This is perhaps best shown with an example. Let’s extend the createGreeting
function that we built in the previous section of this chapter:
func createGreeting(greeting string) func(string) string { return func(name string) string { return greeting + name } }
The change we have made here is to have the greeting passed as an input...