Say we need to sort a slice of custom type elements. We can do this in 2 ways:
- We wrap the underlying slice with a custom type that implements the
sort.Interface
with the methods that encapsulate the sorting algorithm. - We define a closure encapsulating the sorting algorithm and pass it to the
sort.Slice
function.
See the example for details.
-
Run the program.
$ make run