Add functional predicate XNOR (#181)

Add new function, Xnor, designed to create a composed predicate representing
the logical Exclusive NOR (XNOR) operation applied to a list of predicates.
The XNOR operation is a logical operation that returns true only
if all operands have the same boolean value
This commit is contained in:
donutloop
2024-02-25 13:24:47 +01:00
committed by GitHub
parent aebab7c944
commit a43bc554ee
3 changed files with 62 additions and 0 deletions

View File

@@ -73,6 +73,22 @@ func ExampleNor() {
// false
}
func ExampleXnor() {
isEven := func(i int) bool { return i%2 == 0 }
isPositive := func(i int) bool { return i > 0 }
match := Xnor(isEven, isPositive)
fmt.Println(match(2))
fmt.Println(match(-3))
fmt.Println(match(3))
// Output:
// true
// true
// false
}
// func ExamplePredicatesMix() {
// a := Or(
// func(s string) bool { return strings.ContainsAny(s, "0123456789") },