SortMaps returns a [cmp.Transformer] option that flattens map[K]V types to be a sorted []struct{K, 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 map with key K that is ass
(lessOrCompareFunc interface{})
| 117 | // |
| 118 | // SortMaps can be used in conjunction with [EquateEmpty]. |
| 119 | func SortMaps(lessOrCompareFunc interface{}) cmp.Option { |
| 120 | vf := reflect.ValueOf(lessOrCompareFunc) |
| 121 | if (!function.IsType(vf.Type(), function.Less) && !function.IsType(vf.Type(), function.Compare)) || vf.IsNil() { |
| 122 | panic(fmt.Sprintf("invalid less or compare function: %T", lessOrCompareFunc)) |
| 123 | } |
| 124 | ms := mapSorter{vf.Type().In(0), vf} |
| 125 | return cmp.FilterValues(ms.filter, cmp.Transformer("cmpopts.SortMaps", ms.sort)) |
| 126 | } |
| 127 | |
| 128 | type mapSorter struct { |
| 129 | in reflect.Type // T |