It seems that https://godoc.org/sort#Interface is the way to go here. You can combine it with reflect.Swapper to get an API like https://godoc.org/sort#Slice
On Wed, Jan 31, 2018 at 6:52 PM, Chris Hopkins <cbehopk...@gmail.com> wrote: > Okay well the actual (working version) of the code (before I wrote the > test cases that are currently failing/not compiling) is here (I refuse to > check in broken code): > https://github.com/cbehopkins/permutation/blob/master/helpers.go > > The source library (permutation) can cope with permutes on arrays of > arbitrary type as long as you supply a Less function. I'm trying to extend > the test cases so anything other than int type is tested. > I've long preached that is you're using reflect you're probably doing it. > I know the source library uses reflect for these things, I'm trying to > avoid it. > > I just can't see a different way to do it. > > Thanks > Chris > > On Wednesday, 31 January 2018 17:46:51 UTC, Axel Wagner wrote: >> >> FTR, you can also pass an actual []Usable, instead of a []tmpType. That >> is do >> https://play.golang.org/p/N_CJh0Ekik8 >> But I do think that your code and question suggest that you are trying to >> use interfaces to do some sort of subtyping, which is just not how they are >> supposed to be used. >> >> On Wed, Jan 31, 2018 at 6:43 PM, Axel Wagner <axel.wa...@googlemail.com> >> wrote: >> >>> You have to use reflection for that. Go doesn't have subtyping of that >>> kind. This smells a bit of an xy-problem <http://xyproblem.info/> to >>> me, though. There are several things here, that suggest an antipattern >>> going on. With a little bit of context on the actual problem you are trying >>> to solve, we might be able to come up with a more idiomatic design. >>> >>> On Wed, Jan 31, 2018 at 6:37 PM, Chris Hopkins <cbeho...@gmail.com> >>> wrote: >>> >>>> Hi >>>> Sharing my ignorance: >>>> I didn't realise that although you can switch-case on an interface, an >>>> array of interfaces doesn't work. >>>> https://play.golang.org/p/tD8msjCXyuZ >>>> >>>> Any ideas on how to cope with this? I tried: >>>> _, ok = tmp.([]Useable) >>>> >>>> But that fails for the same reason. I can't work out how to detect if >>>> the type (of the empty interface) is an array of a type that satisfies the >>>> (useful) interface. >>>> This must be a common problem and PEBKAC surely? >>>> >>>> Regards >>>> >>>> Chris >>>> >>>> -- >>>> 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...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >> -- > 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. > For more options, visit https://groups.google.com/d/optout. > -- 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. For more options, visit https://groups.google.com/d/optout.