Proposal Details
An addition to the cmp package to support a common use case in ordered comparison.
func CompareBy[K cmp.Ordered, V any](key func(V) K) func(V, V) int {
return func(a, b V) int { return cmp.Compare(key(a), key(b)) }
}
The majority of custom comparison functions apply the same transformation to each element. Analogous to Python's key functions, and would integrate well with Reverse proposed in #65632.
Proposal Details
An addition to the
cmppackage to support a common use case in ordered comparison.The majority of custom comparison functions apply the same transformation to each element. Analogous to Python's key functions, and would integrate well with
Reverseproposed in #65632.