On Tue, Nov 8, 2022 at 10:56 AM 'Mark' via golang-nuts <golang-nuts@googlegroups.com> wrote: > ////// Want to sort by T < T ////////////////// > elements := make([]string, 0, len(me)) > for element := range me { > elements = append(elements, fmt.Sprintf("%#v", element)) > } > sort.Strings(elements) > /////////////////////////////////////////////////////
Not tested: ////// Want to sort by T < T ////////////////// elements := make([]T, 0, len(me)) for element := range me { elements = append(elements, element) } sort.Slice(elements, func(i, j int) bool { return less(elements[i], elements[j]) }) ///////////////////////////////////////////////////// But you need to extend the less function to handle mixed types. Like in less(42, "foo"). -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-UC7NevL7EtrLNb9rJRDSXDtf9AaZ-FX497b41XR2jJ5A%40mail.gmail.com.