Created
May 16, 2022 05:40
-
-
Save sausheong/567c028d9e184585ad487f5c8610815b to your computer and use it in GitHub Desktop.
generics
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
import "golang.org/x/exp/constraints" | |
type Number interface { | |
constraints.Integer | constraints.Float | |
} | |
func AddNumbers[T Number](a, b T) T { | |
return a + b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment