Created
October 13, 2011 14:18
-
-
Save dagoof/1284323 to your computer and use it in GitHub Desktop.
quick test of first class functions in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type IntegerReduce func(...int) int | |
func main() { | |
sum := func(n ...int) int { | |
sum := 0 | |
for _, v := range n { | |
sum += v | |
} | |
return sum | |
} | |
partial := func(f IntegerReduce, n ...int) IntegerReduce { | |
return func(m ...int) int { | |
return f(append(n, m...)...) | |
} | |
} | |
fmt.Println(sum(1, 2, 7, 9)) | |
fmt.Println(partial(sum, 1, 2)(7, 9)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment