v0.0.526
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m17s

This commit is contained in:
Mike Schwörer 2024-10-05 23:59:23 +02:00
parent a7389f44fa
commit cfb0b53fc7
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 27 additions and 2 deletions

View File

@ -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"

View File

@ -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: