Skip to content

Instantly share code, notes, and snippets.

@ijt ijt/splat.go
Created Oct 26, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.