3 ms·
If the order matters, it's only as hard as using a (different) data structure that preserves order.
by evmar 5y ago
If the order matters, it's only as hard as using a (different) data structure that preserves order.
- masklinn 5y ago> it's only as hard as using a (different) data structure that preserves order. Which turns out to be pretty inconvenient in Go. So more likely you’d do something like copy the keys to a slice, sort the slice, then iterate that to get the map values. Incidentally, that’s exactly what the json package does when encoding a map.
- wyager 5y agoNow you’re stuck with the fact that Go doesn’t support generics outside of the stock data structures.