Skip to content

Instantly share code, notes, and snippets.

@ijt
Created October 26, 2012 20:22
Show Gist options
  • Save ijt/3961264 to your computer and use it in GitHub Desktop.
Save ijt/3961264 to your computer and use it in GitHub Desktop.
Argument splatting in Go
// See https://code.google.com/p/go/issues/detail?id=640
package main
import "fmt"
func main() {
args := []int{1, 2, 3}
fmt.Println(sum(args...))
}
func sum(args ...int) int {
s := 0
for _, a := range(args) {
s += a
}
return s
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment