Skip to content

Instantly share code, notes, and snippets.

@dagoof
Created October 13, 2011 14:18
Show Gist options
  • Save dagoof/1284323 to your computer and use it in GitHub Desktop.
Save dagoof/1284323 to your computer and use it in GitHub Desktop.
quick test of first class functions in go
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