Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created January 9, 2022 14:22
Show Gist options
  • Save percybolmer/d12c24c6a71ac827ba7d555913406d24 to your computer and use it in GitHub Desktop.
Save percybolmer/d12c24c6a71ac827ba7d555913406d24 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main(){
var a int = 20
var b int = 10
// the compiler will infere the type used
result := Subtract(a, b)
fmt.Println("Result: ", result)
}
// We define the Type parameter V, which is a int, int32 or float32
// We also say that function parameter a and b has the data type of V
// We then make the function return V
func Subtract[V int | int32 | float32 ](a, b V) V {
return a - b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment