Last active
January 17, 2023 14:49
-
-
Save gsrai/4e7321a790bdd3cfc2c3f5cfa16810b0 to your computer and use it in GitHub Desktop.
get the keys of any map in go
This file contains hidden or 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
package utils | |
func GetKeys[K comparable, V any](m map[K]V) []K { | |
keys := make([]K, 0, len(m)) | |
for k := range m { | |
keys = append(keys, k) | |
} | |
return keys | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment