Created
November 10, 2017 18:07
-
-
Save nycdavid/cbbc5d6e1d035636e5de71509bee393e to your computer and use it in GitHub Desktop.
Sample code for interface post
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"bytes" | |
"strconv" | |
) | |
type operand interface { | |
} | |
func main() { | |
fmt.Println("Hello!") | |
Addition(1, "foo", 2, "bar", 3, "baz") | |
} | |
func Addition(operands ...operand) { | |
var buf bytes.Buffer | |
for idx, operand := range operands { | |
switch operand.(type) { | |
case int: | |
buf.WriteString(strconv.Itoa(operand.(int))) | |
case string: | |
buf.WriteString(operand.(string)) | |
} | |
if idx != len(operands) - 1 { | |
buf.WriteString(" + ") | |
} | |
} | |
fmt.Println(buf.String()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment