Re:Go by Example
by a-nom-a-ly on Friday January 17, 2014 @05:11PM
(#7078784)
You can do this just as easily in Go as well, using reflection.
[ Parent
| on HN ]
Re:Go by Example
by burntsushi on Friday January 17, 2014 @05:39PM
(#7078956)
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