diff --git a/collections/maps.go b/collections/maps.go index 2cbf916..3702603 100644 --- a/collections/maps.go +++ b/collections/maps.go @@ -111,3 +111,12 @@ func IniToMap(path string) map[string]string { } return result } + +func MapKeys[K comparable](m map[K]any) []K { + keys := make([]K, 0, len(m)) + for k := range m { + keys = append(keys, k) + } + + return keys +} diff --git a/utils/utils.go b/utils/utils.go index 69ee04b..f089e23 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -15,6 +15,22 @@ import ( log "github.com/sirupsen/logrus" ) +func Ptr[T any](value T) *T { + return &value +} + +// Coalesce returns the first non-zero element +func Coalesce[T comparable](arr ...T) T { + var zeroVal T + for _, item := range arr { + if item != zeroVal { + return item + } + } + + return zeroVal +} + // GetEnvOrDefault returns the first non-empty environment variable func GetEnvOrDefault(names ...string) string { for _, name := range names {