SortSlices returns a [cmp.Transformer] option that sorts all []V. The lessOrCompareFunc function must be either a less function of the form "func(T, T) bool" or a compare function of the format "func(T, T) int" which is used to sort any slice with element type V that is assignable to T. A less func
(lessOrCompareFunc interface{})
| 34 | // |
| 35 | // SortSlices can be used in conjunction with [EquateEmpty]. |
| 36 | func SortSlices(lessOrCompareFunc interface{}) cmp.Option { |
| 37 | vf := reflect.ValueOf(lessOrCompareFunc) |
| 38 | if (!function.IsType(vf.Type(), function.Less) && !function.IsType(vf.Type(), function.Compare)) || vf.IsNil() { |
| 39 | panic(fmt.Sprintf("invalid less or compare function: %T", lessOrCompareFunc)) |
| 40 | } |
| 41 | ss := sliceSorter{vf.Type().In(0), vf} |
| 42 | return cmp.FilterValues(ss.filter, cmp.Transformer("cmpopts.SortSlices", ss.sort)) |
| 43 | } |
| 44 | |
| 45 | type sliceSorter struct { |
| 46 | in reflect.Type // T |