November 2017
Intermediate to advanced
670 pages
17h 35m
English
Our third option is called partial application. We can accomplish this with currying.
The idea behind currying is to create new, more specific functions from other more general functions by partially applying them.
Consider that we have have an add function that takes two numbers:
func add(x, y int) int { return x + y}
We can create another function that returns the add function with one of the parameters pre-inserted. We'll take a simple example of adding one to any other number:
func addOnePartialFn() func(int) int { return func(y int) int { return add(1, y) }}
The results of calling add(1,2) will be the same as calling addOne(2):
func main() { fmt.Printf("add(1, 2): %d\n", add(1, 2)) addOne := addOnePartialFn() fmt.Printf( ...