Created
January 10, 2019 02:56
-
-
Save crhntr/59dbc7bdb72b7469a050e5d5986202da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sort "generic" | |
// https://medium.com/capital-one-tech/closures-are-the-generics-for-go-cb32021fb5b5 | |
type sorter struct { | |
len int | |
swap func(i, j int) | |
less func(i, j int) bool | |
} | |
func (x sorter) Len() int { return x.len } | |
func (x sorter) Swap(i, j int) { x.swap(i, j) } | |
func (x sorter) Less(i, j int) bool { return x.less(i, j) } | |
func sortThis(n int, swap func(i, j int), less func(i, j int) bool) { sort.Sort(sorter{n, swap, less}) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment