You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
420 B

2 years ago
2 years ago
  1. package gentools
  2. func CopyMap[K comparable, V any](m map[K]V) map[K]V {
  3. m2 := make(map[K]V, len(m)+1)
  4. for k, v := range m {
  5. m2[k] = v
  6. }
  7. return m2
  8. }
  9. func OneItemMap[K comparable, V any](key K, value V) map[K]V {
  10. m := make(map[K]V, 1)
  11. m[key] = value
  12. return m
  13. }
  14. func MapKeys[K comparable, V any](m map[K]V) []K {
  15. keys := make([]K, 0, len(m))
  16. for key := range m {
  17. keys = append(keys, key)
  18. }
  19. return keys
  20. }