# README
The deriveKeys function returns a map's keys as a slice. It is especially useful in combination with the deriveSort function, when you want to deterministically range over a map.
Given the following input:
package keys
import (
"strconv"
)
func printMap(m map[string]int) {
for _, k := range deriveSort(deriveKeys(m)) {
println(k + ":" + strconv.Itoa(m[k]))
}
}
goderive will generate the following code:
// Code generated by goderive DO NOT EDIT.
package keys
import (
"sort"
)
// deriveSort sorts the slice inplace and also returns it.
//
// Deprecated: In favour of generics.
func deriveSort(list []string) []string {
sort.Strings(list)
return list
}
// deriveKeys returns the keys of the input map as a slice.
//
// Deprecated: In favour of generics.
func deriveKeys(m map[string]int) []string {
keys := make([]string, 0, len(m))
for key := range m {
keys = append(keys, key)
}
return keys
}