diff options
author | Nami-Doc <vendethiel@hotmail.fr> | 2014-01-29 13:14:37 -0800 |
---|---|---|
committer | Nami-Doc <vendethiel@hotmail.fr> | 2014-01-29 13:14:37 -0800 |
commit | 066dc1b257b932cce89dacd2c4cad5ba61c07523 (patch) | |
tree | e16f0652ea1f8910008a4249fefec6fd3dba3eb8 | |
parent | 041792ef0bea792a3caa7efc32ec322db9b4edbf (diff) | |
parent | 863194a89aa98fd446910246980e7c4ba8954cfa (diff) |
Merge pull request #502 from cbess/master
[go/en] Add variadic function example
-rw-r--r-- | go.html.markdown | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/go.html.markdown b/go.html.markdown index ee41642a..d68ba51b 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -5,6 +5,7 @@ language: Go filename: learngo.go contributors: - ["Sonia Keys", "https://github.com/soniakeys"] + - ["Christopher Bess", "https://github.com/cbess"] --- Go was created out of the need to get work done. It's not the latest trend @@ -175,7 +176,20 @@ func learnFlowControl() { goto love love: - learnInterfaces() // Good stuff coming up! + // Good stuff coming up! + learnVariadicParams("great", "learning", "here!") + learnInterfaces() +} + +// Functions can have variadic parameters +func learnVariadicParams(myStrings ...string) { + // iterate each value of the variadic + for _, param := range myStrings { + fmt.Println("param:", param) + } + + // pass variadic value as a variadic parameter + fmt.Println("params:", fmt.Sprintln(myStrings...)) } // Define Stringer as an interface type with one method, String. |