--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I want to write three different go functions that sorts based on age, name and sal.
- declare a named type of slice
- implement 3 methods Len, Less, Swap
- call sort.Sort
(each attribute age, name, sal, needs its own type declaration and 3 method implementations).
Since Go 1.8, we can achieve basically the same with much less boilerplate code (as showcased here and here) :
- implement 1 func "less" having type func(i, j int) bool
- call sort.Slice
(each attribute age, name, sal, needs its own "less" func).
I suggest the latter.
HTH
Valentin
Oh, thanks a lot Egon,Your neat and elegant code is very helpful for me to get the idea and get started.Just FTA, in case someone is also reading this, more onto sorting the slice, here is my archive from this list: