MapKeys converts a map's keys to a slice. The order of elements is not guaranteed as map iteration order is undefined. This is a pure function that does not modify the input map.
(m map[K]V)
| 37 | // The order of elements is not guaranteed as map iteration order is undefined. |
| 38 | // This is a pure function that does not modify the input map. |
| 39 | func MapKeys[K comparable, V any](m map[K]V) []K { |
| 40 | result := make([]K, 0, len(m)) |
| 41 | for key := range m { |
| 42 | result = append(result, key) |
| 43 | } |
| 44 | return result |
| 45 | } |
| 46 | |
| 47 | // FilterMapKeys returns map keys that match the given predicate. |
| 48 | // The order of elements is not guaranteed as map iteration order is undefined. |
no outgoing calls