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:
parent
a7389f44fa
commit
cfb0b53fc7
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.525"
|
||||
const GoextVersion = "0.0.526"
|
||||
|
||||
const GoextVersionTimestamp = "2024-10-05T02:45:20+0200"
|
||||
const GoextVersionTimestamp = "2024-10-05T23:59:23+0200"
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user