mirror of
https://github.com/duke-git/lancet.git
synced 2025-10-05 23:46:54 +08:00
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:
@@ -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") },
|
||||
|
Reference in New Issue
Block a user