At its core, this is this restriction of the current generics design: https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#no-way-to-require-pointer-methods That is, there is no real "nice" way to do it.
If you are willing to require a pointer receiver, you can do constraint type inference: https://go.dev/play/p/L2NiAAM8qE4 Alternatively, it might be appropriate to do away with methods and pass a comparison function: https://go.dev/play/p/XRoD70UFbzi This has the advantage of being able to use types which you don't control as well. On Thu, Apr 7, 2022 at 10:07 AM jfcg...@gmail.com <jfcga...@gmail.com> wrote: > Hi, please take a look <https://go.dev/play/p/aKekf6a4VRh>. > > The aim is to write a HaveLess constraint that will work with any type > like Large, without any reflection / traditional interfaces / > dictionaries etc., just plain method calls. > > How would you write this? Keep in mind that type Large is large :) > > -- > 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/e79c4f92-4508-4ecd-ab32-c47b2d679f78n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/e79c4f92-4508-4ecd-ab32-c47b2d679f78n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAEkBMfFhuwgy4HM%3DP7vRYyUDfsnj1ZhdnvctKqQFNkiVprFCYA%40mail.gmail.com.