This commit is contained in:
Steven Degutis
2012-03-16 07:17:07 -05:00
parent 0bc49e55a4
commit a1877bcd5f
2 changed files with 22 additions and 2 deletions

View File

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