Hacker News new | ask | show | jobs
by a-nom-a-ly 4529 days ago
You can do this just as easily in Go as well, using reflection.
1 comments

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