Created
January 9, 2022 14:22
-
-
Save percybolmer/d12c24c6a71ac827ba7d555913406d24 to your computer and use it in GitHub Desktop.
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" | |
) | |
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