// SortSlices returns a [cmp.Transformer] option that sorts all []V. // The less function must be of the form "func(T, T) bool" which is used to // sort any slice with element type V that is assignable to T. // // The less function must be: // - Deterministic: less(x, y) == less(x, y) // - Irreflexive: !less(x, x) // - Transitive: if !less(x, y) and !less(y, z), then !less(x, z) // // The less function does not have to be "total". That is, if !less(x, y) and // !less(y, x) for two elements x and y, their relative order is maintained. // // SortSlices can be used in conjunction with [EquateEmpty]. func SortSlices(lessFunc interface{ … } type sliceSorter … func (ss sliceSorter) filter(x, y interface{ … } func (ss sliceSorter) sort(x interface{ … } func (ss sliceSorter) checkSort(v reflect.Value) { … } func (ss sliceSorter) less(v reflect.Value, i, j int) bool { … } // SortMaps returns a [cmp.Transformer] option that flattens map[K]V types to be a // sorted []struct{K, V}. The less function must be of the form // "func(T, T) bool" which is used to sort any map with key K that is // assignable to T. // // Flattening the map into a slice has the property that [cmp.Equal] is able to // use [cmp.Comparer] options on K or the K.Equal method if it exists. // // The less function must be: // - Deterministic: less(x, y) == less(x, y) // - Irreflexive: !less(x, x) // - Transitive: if !less(x, y) and !less(y, z), then !less(x, z) // - Total: if x != y, then either less(x, y) or less(y, x) // // SortMaps can be used in conjunction with [EquateEmpty]. func SortMaps(lessFunc interface{ … } type mapSorter … func (ms mapSorter) filter(x, y interface{ … } func (ms mapSorter) sort(x interface{ … } func (ms mapSorter) checkSort(v reflect.Value) { … } func (ms mapSorter) less(v reflect.Value, i, j int) bool { … }