IgnoreSliceElements returns an [cmp.Option] that ignores elements of []V. The discard function must be of the form "func(T) bool" which is used to ignore slice elements of type V, where V is assignable to T. Elements are ignored if the function reports true.
(discardFunc interface{})
| 153 | // ignore slice elements of type V, where V is assignable to T. |
| 154 | // Elements are ignored if the function reports true. |
| 155 | func IgnoreSliceElements(discardFunc interface{}) cmp.Option { |
| 156 | vf := reflect.ValueOf(discardFunc) |
| 157 | if !function.IsType(vf.Type(), function.ValuePredicate) || vf.IsNil() { |
| 158 | panic(fmt.Sprintf("invalid discard function: %T", discardFunc)) |
| 159 | } |
| 160 | return cmp.FilterPath(func(p cmp.Path) bool { |
| 161 | si, ok := p.Index(-1).(cmp.SliceIndex) |
| 162 | if !ok { |
| 163 | return false |
| 164 | } |
| 165 | if !si.Type().AssignableTo(vf.Type().In(0)) { |
| 166 | return false |
| 167 | } |
| 168 | vx, vy := si.Values() |
| 169 | if vx.IsValid() && vf.Call([]reflect.Value{vx})[0].Bool() { |
| 170 | return true |
| 171 | } |
| 172 | if vy.IsValid() && vf.Call([]reflect.Value{vy})[0].Bool() { |
| 173 | return true |
| 174 | } |
| 175 | return false |
| 176 | }, cmp.Ignore()) |
| 177 | } |
| 178 | |
| 179 | // IgnoreMapEntries returns an [cmp.Option] that ignores entries of map[K]V. |
| 180 | // The discard function must be of the form "func(T, R) bool" which is used to |