Created
October 26, 2012 20:22
-
-
Save ijt/3961264 to your computer and use it in GitHub Desktop.
Argument splatting 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
// 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