not.go 396 B

123456789101112131415161718192021
  1. package matcher
  2. import "fmt"
  3. // Not negates any filter contained within it
  4. type Not[T any] struct {
  5. Matcher Matcher[T]
  6. }
  7. func (n *Not[T]) Add(m Matcher[T]) {
  8. n.Matcher = m
  9. }
  10. func (n *Not[T]) String() string {
  11. return fmt.Sprintf("(not %s)", n.Matcher.String())
  12. }
  13. // Matches inverts the result of the child matcher
  14. func (n *Not[T]) Matches(that T) bool {
  15. return !n.Matcher.Matches(that)
  16. }