From the docs, “Reverse returns the reverse order for data.” so shouldn’t sort.Reverse sort in reverse order and then sort.Sort put the slice back into normal order again? Instead if I just do sort.Reverse nothing appears to happen.
The documentation says sort.Sort gets a sort.Interface, not a slice!
The interface implements three methods, Len, Swap and Less. Less, given two elements of the slice, returns true if the first is element is to be put before the second element.
sort.Reverse takes the sort.Interface and just negates Less, inverting its meaning.
I did notice the interface mention rather than a slice but didn’t really take it in. That description is a good one and makes sense, I’ll build a couple of examples up so I can see it in action. Thanks.
I’ve had a play and it all seems to make sense, how does this look for sorting
a key/value struct by either keys or values and being able to reverse the sort?