4 ms·
ah, SliceStable does make it a little easier at least. I'd say you could just wrap that in a function, but you can't easily do that. Sorting is probably the o
by justinsaccount 10y ago
ah, SliceStable does make it a little easier at least. I'd say you could just wrap that in a function, but you can't easily do that.
Sorting is probably the one area where I really miss generics in go.. because comparing and sorting IS such a generic thing to do. In my head I think, "Oh, so I just want to do
hosts.sort(key=operator.attrgetter("os", "version", "address"))
and then proceed to write the 20 lines of code that lets me do that :-(
- grey-area 10y agoJust thought of one more way to do this which is neater - define functions on a simpler slice type: https://play.golang.org/p/0YcxA-Ufs- https://play.golang.org/p/0YcxA-Ufs- So your sorting becomes quite neat: sort.SliceStable(changes,changes.byLines) sort.SliceStable(changes,changes.byUser) I think I might use it this way (haven't actually used this in a real app yet).
- SaidinWoT 10y agoPerhaps something combining all of the things you've made use of? https://play.golang.org/p/8RDqjjZDB8 https://play.golang.org/p/8RDqjjZDB8