diff --git a/goextVersion.go b/goextVersion.go index 638f952..90020c6 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -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" diff --git a/langext/coalesce.go b/langext/coalesce.go index bc9e3c9..5c5b361 100644 --- a/langext/coalesce.go +++ b/langext/coalesce.go @@ -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: