Add a generic Values()

This commit is contained in:
Kovid Goyal 2022-12-01 13:47:06 +05:30
parent f29ce19097
commit 3601488b26
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -98,3 +98,15 @@ func Keys[M ~map[K]V, K comparable, V any](m M) []K {
} }
return r return r
} }
// Values returns the values of the map m.
// The values will be an indeterminate order.
func Values[M ~map[K]V, K comparable, V any](m M) []V {
r := make([]V, len(m))
i := 0
for _, v := range m {
r[i] = v
i++
}
return r
}