initial commit
This commit is contained in:
24
backend/pkg/values/values.go
Normal file
24
backend/pkg/values/values.go
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user