2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-05-19 19:21:44 +00:00
|
|
|
package maps
|
|
|
|
|
|
|
|
func SliceOfKeys[K comparable, V any](m map[K]V) []K {
|
|
|
|
if len(m) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
res := make([]K, 0, len(m))
|
|
|
|
for k := range m {
|
|
|
|
res = append(res, k)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|
2022-06-27 19:37:18 +00:00
|
|
|
|
|
|
|
func SliceOfValues[K comparable, V any](m map[K]V) []V {
|
|
|
|
if len(m) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
res := make([]V, 0, len(m))
|
|
|
|
for _, v := range m {
|
|
|
|
res = append(res, v)
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
}
|