3 ms·
I have a question about go. Let's say I have a struct Foo and a function/method for Less. What is the quickest way to sort an array of Foo's? Do I have to impl
by herge 13y ago
I have a question about go. Let's say I have a struct Foo and a function/method for Less. What is the quickest way to sort an array of Foo's?
Do I have to implement my own []Foo type with all three methods as described in the sort package?
- nickpresta 13y agohttp://golang.org/pkg/sort/#example_Interface http://golang.org/pkg/sort/#example_Interface
- herge 13y agoSo the answer is yes, I have to implement the whole interface?
- stonemetal 13y agoYes, to use code that relies on an interface you must implement the interface for your types. That is one of the reasons go has a guiding design principle that interfaces should be as small as possible.
- bouk 13y agoYes, generics are not (yet??) possible in go