MCPcopy
hub / github.com/google/go-cmp / FilterValues

Function FilterValues

cmp/options.go:159–172  ·  view source on GitHub ↗

FilterValues returns a new [Option] where opt is only evaluated if filter f, which is a function of the form "func(T, T) bool", returns true for the current pair of values being compared. If either value is invalid or the type of the values is not assignable to T, then this filter implicitly returns

(f interface{}, opt Option)

Source from the content-addressed store, hash-verified

157// The option passed in may be an [Ignore], [Transformer], [Comparer], [Options], or
158// a previously filtered [Option].
159func FilterValues(f interface{}, opt Option) Option {
160 v := reflect.ValueOf(f)
161 if !function.IsType(v.Type(), function.ValueFilter) || v.IsNil() {
162 panic(fmt.Sprintf("invalid values filter function: %T", f))
163 }
164 if opt := normalizeOption(opt); opt != nil {
165 vf := &valuesFilter{fnc: v, opt: opt}
166 if ti := v.Type().In(0); ti.Kind() != reflect.Interface || ti.NumMethod() > 0 {
167 vf.typ = ti
168 }
169 return vf
170 }
171 return nil
172}
173
174type valuesFilter struct {
175 core

Callers 11

comparerTestsFunction · 0.92
transformerTestsFunction · 0.92
ExampleOption_equalEmptyFunction · 0.92
SortSlicesFunction · 0.92
SortMapsFunction · 0.92
EquateEmptyFunction · 0.92
EquateApproxFunction · 0.92
EquateNaNsFunction · 0.92
EquateApproxTimeFunction · 0.92
EquateErrorsFunction · 0.92

Calls 4

IsTypeFunction · 0.92
normalizeOptionFunction · 0.85
IsNilMethod · 0.80
TypeMethod · 0.65

Tested by 4

comparerTestsFunction · 0.74
transformerTestsFunction · 0.74
ExampleOption_equalEmptyFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…