Files
go-koans/about_variadic_functions.go
Tommy Parnell a7d91efcfc finished woo
2017-07-08 01:22:34 -04:00

21 lines
525 B
Go

package go_koans
import "strings"
func concatNames(sep string, names ...string) string {
return strings.Join(names, sep) // variadic parameters are really just slices
}
func aboutVariadicFunctions() {
{
str := concatNames(" ", "bob", "billy", "fred")
assert(str == "bob billy fred") // several values can be passed to variadic parameters
}
{
names := []string{"bob", "billy", "fred"}
str := concatNames("-", names...)
assert(str == "bob-billy-fred") // or a slice can be dotted in place of all of them
}
}