sort
package:
type Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
}
...
type reverse struct {
Interface
}
The statement
type reverse struct {
Interface
}
enables you to initialize reverse
with everything that implements the interface Interface
. Example:
&reverse{sort.Intslice([]int{1,2,3})}
This way, all methods implemented by the embedded Interface
value get populated to the outside while you are still able to override some of them in reverse
, for example Less
to reverse the sorting.
This is what actually happens when you use sort.Reverse. You can read about embedding in the struct section of the spec.