Update generics.go

I just remove the make function from the MapKeys method, the new version looks cleaner.
This commit is contained in:
Orhan Erday 2022-09-26 16:06:54 +03:00 committed by GitHub
parent 4f668ee955
commit 257177d382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,7 +14,7 @@ import "fmt"
// `V` has the `any` constraint, meaning that it's not
// restricted in any way (`any` is an alias for `interface{}`).
func MapKeys[K comparable, V any](m map[K]V) []K {
r := make([]K, 0, len(m))
var r []K
for k := range m {
r = append(r, k)
}