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)
| 157 | // The option passed in may be an [Ignore], [Transformer], [Comparer], [Options], or |
| 158 | // a previously filtered [Option]. |
| 159 | func 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 | |
| 174 | type valuesFilter struct { |
| 175 | core |
searching dependent graphs…