From abcd36fec036f573ca9f22c89bbf583ebde42609 Mon Sep 17 00:00:00 2001 From: Steve Krulewitz Date: Tue, 24 Feb 2015 14:54:33 -0800 Subject: [PATCH] Complete TODO for coalesced function parameters. --- examples/functions/functions.go | 13 +++++++++++-- examples/functions/functions.sh | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/functions/functions.go b/examples/functions/functions.go index a590ca9..1895fc8 100644 --- a/examples/functions/functions.go +++ b/examples/functions/functions.go @@ -15,12 +15,21 @@ func plus(a int, b int) int { return a + b } +// When you have multiple consecutive parameters of +// the same type, you may omit the type name for the +// like-typed parameters up to the final parameter that +// declares the type. +func plusPlus(a, b, c int) int { + return a + b + c +} + func main() { // Call a function just as you'd expect, with // `name(args)`. res := plus(1, 2) fmt.Println("1+2 =", res) -} -// todo: coalesced parameter types + res = plusPlus(1, 2, 3) + fmt.Println("1+2+3 =", res) +} diff --git a/examples/functions/functions.sh b/examples/functions/functions.sh index 266aec0..cc8ff15 100644 --- a/examples/functions/functions.sh +++ b/examples/functions/functions.sh @@ -1,5 +1,6 @@ $ go run functions.go 1+2 = 3 +1+2+3 = 6 # There are several other features to Go functions. One is # multiple return values, which we'll look at next.