all: sync with master

This commit is contained in:
Ainar Garipov
2022-08-17 18:23:30 +03:00
parent 3c17853344
commit 9200163f85
25 changed files with 740 additions and 326 deletions

View File

@@ -10,6 +10,20 @@ import (
"golang.org/x/exp/slices"
)
// Coalesce returns the first non-zero value. It is named after the function
// COALESCE in SQL. If values or all its elements are empty, it returns a zero
// value.
func Coalesce[T comparable](values ...T) (res T) {
var zero T
for _, v := range values {
if v != zero {
return v
}
}
return zero
}
// UniqChecker allows validating uniqueness of comparable items.
//
// TODO(a.garipov): The Ordered constraint is only really necessary in Validate.