Files
aethera/backend/pkg/values/values.go
2026-01-17 10:09:11 -05:00

25 lines
465 B
Go

package values
// FirstNonZero will return the first non zero value. If none exists,
// it returns the zero value.
func FirstNonZero[T comparable](vals ...T) T {
var zeroT T
for _, v := range vals {
if v != zeroT {
return v
}
}
return zeroT
}
// CountNonZero returns the count of items that are non zero
func CountNonZero[T comparable](vals ...T) (count int) {
var zeroT T
for _, v := range vals {
if v != zeroT {
count++
}
}
return count
}