|
|
|
|
|
by burntsushi
4529 days ago
|
|
Yup! Here ya go: // Sort a slice of structs with first class functions.
type Album struct {
Title string
Year int
}
albums := []Album{
{"Born to Run", 1975},
{"WIESS", 1973},
{"Darkness", 1978},
{"Greetings", 1973},
}
less := func(a, b Album) bool { return a.Year < b.Year },
sorted := QuickSort(less, albums).([]Album)
For more fun things, see: http://godoc.org/github.com/BurntSushi/ty/fun |
|