math
math copied to clipboard
Max/Min for Slice of Structs
Hello Dave,
Thanks for the great package! I was looking for an elegant way of getting max/min of a slice of structs.
// Example
type benchmark struct {
time int
size int
}
// Given
var benchmarks []benchmark
/*
I sometimes need to find one of the following benchmarks
- fastest (min time)
- slowest (max time)
- smallest (min size)
- largest (max size)
*/
Hmm. I don’t see how to do that without using interface{}. If you can think of a way, please feel free to send a pr