Description
cmp.FilterValues
expects a function of the signature func(T, T) bool
where the function is called with values from both the left argument and the right argument.
I propose the addition of cmpopts.FilterValue
that is semantically equivalent to:
func FilterValue[T any](f func(T) bool) cmp.Option {
return cmp.FilterValues(func(x, y T) bool {
return f(x) && f(y)
})
}
The current cmp.FilterValues
is more powerful as you can make a filtering decision based on information from both values, but most usages of it want the logical AND of a single-argument predicate function. In fact, all of the usages of cmp.FilterValues
in cmpopts
would prefer to use a single-argument predicate function. Examples:
Lines 26 to 31 in 6faefd0
Lines 60 to 62 in 6faefd0
Lines 85 to 87 in 6faefd0
Lines 104 to 106 in 6faefd0
Lines 144 to 148 in 6faefd0
Alternatively, we could modify cmp.FilterValues
to also accept a function of the form func(T) bool
where it effectively performs the AND of the predicate function applies to both arguments.
\cc @neild