3 ms·
You can do this just as easily in Go as well, using reflection.
by a-nom-a-ly 13y ago
You can do this just as easily in Go as well, using reflection.
- burntsushi 13y agoYup! 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 http://godoc.org/github.com/BurntSushi/ty/fun