Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/20250815151015.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
✨ [collection] Add ConvertMapToLoggerValues function for logr.Logger compatibility
12 changes: 12 additions & 0 deletions utils/collection/parseLists.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ func ConvertMapToSlice[K comparable, V any](pairs map[K]V) []string {
return slice
}

// ConvertMapToLoggerValues is similar to ConvertMapToSlice but returns a type compatible with logr.Logger.
func ConvertMapToLoggerValues[K comparable, V any](pairs map[K]V) []any {
if len(pairs) == 0 {
return nil
}
slice := make([]any, 0, len(pairs)*2)
for key, value := range pairs {
slice = append(slice, fmt.Sprintf("%v", key), value)
}
return slice
}

// ConvertMapToPairSlice converts a map to list of key value pairs e.g. ["key1=value1", "key2=value2"]
func ConvertMapToPairSlice[K comparable, V any](pairs map[K]V, pairSeparator string) []string {
if len(pairs) == 0 {
Expand Down
Loading