- Published on
Generics in Go
181 words1 min read
Percent
function that can work with either int
or float64
types.
func Percent[T int | float64](percent T, number T) float64 {
return ((float64(number) * float64(percent)) / float64(100))
}
ArePointersEqual
function that determines if two pointers are equal. Only works with either int
or string
types.
func ArePointersEqual[T int | string](a *T, b *T) bool {
return a == nil && b == nil || a != nil && b != nil && *a == *b
}