Created
March 31, 2023 13:31
-
-
Save neomantra/f1ab990de6b5a9840a9f9dde46f6a7e9 to your computer and use it in GitHub Desktop.
NewPointerValueMap converts a map[string]*T to a map[string]T, omitting nil pointers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NewPointerValueMap converts a map[string]*T to a map[string]T, omitting nil pointers. | |
func NewPointerValueMap[K comparable, V any](src map[K]*V) map[K]V { | |
dst := make(map[K]V) | |
for k, ptr := range src { | |
if ptr != nil { | |
dst[k] = *ptr | |
} | |
} | |
return dst | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment