Skip to content

Instantly share code, notes, and snippets.

@Jagua
Created July 23, 2020 04:49
Show Gist options
  • Save Jagua/2be9ab1d3a00aa318a4d045631e3af42 to your computer and use it in GitHub Desktop.
Save Jagua/2be9ab1d3a00aa318a4d045631e3af42 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type addable interface {
type int, string
}
func add(type T addable)(x, y T) T {
return x + y
}
func main() {
fmt.Printf("%d + %d = %d\n", 1, 1, add(1, 1)) // 1 + 1 = 2
fmt.Printf(`"%s" + "%s" = "%s"` + "\n", "1", "1", add("1", "1")) // "1" + "1" = "11"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment