Skip to content

Instantly share code, notes, and snippets.

@gsrai
Last active January 17, 2023 14:49
Show Gist options
  • Save gsrai/4e7321a790bdd3cfc2c3f5cfa16810b0 to your computer and use it in GitHub Desktop.
Save gsrai/4e7321a790bdd3cfc2c3f5cfa16810b0 to your computer and use it in GitHub Desktop.
get the keys of any map in go
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