math icon indicating copy to clipboard operation
math copied to clipboard

Max/Min for Slice of Structs

Open azimjohn opened this issue 5 years ago • 1 comments

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)
*/

azimjohn avatar Oct 22 '20 17:10 azimjohn

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

davecheney avatar Oct 22 '20 20:10 davecheney