v0.0.526
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m17s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m17s
This commit is contained in:
@@ -133,6 +133,31 @@ func CoalesceStringer(s fmt.Stringer, def string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func CoalesceDefault[T comparable](v1 T, def T) T {
|
||||
if v1 != *new(T) {
|
||||
return v1
|
||||
}
|
||||
|
||||
return def
|
||||
}
|
||||
|
||||
func CoalesceDefaultArr[T comparable](v1 T, vMore ...T) T {
|
||||
if v1 != *new(T) {
|
||||
return v1
|
||||
}
|
||||
if len(vMore) == 0 {
|
||||
return v1
|
||||
}
|
||||
|
||||
for i := 0; i < len(vMore)-1; i++ {
|
||||
if vMore[i] != *new(T) {
|
||||
return v1
|
||||
}
|
||||
}
|
||||
|
||||
return vMore[len(vMore)-1]
|
||||
}
|
||||
|
||||
func SafeCast[T any](v any, def T) T {
|
||||
switch r := v.(type) {
|
||||
case T:
|
||||
|
Reference in New Issue
Block a user