Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type P ¶
P is a predicate function that tests whether a value of type T satisfies some condition.
Example ¶
package main
import (
"fmt"
"github.com/bep/predicate"
)
func main() {
var (
pHello predicate.P[string] = func(s string) bool {
return s == "hello"
}
pWorld predicate.P[string] = func(s string) bool {
return s == "world"
}
pAny predicate.P[string] = func(s string) bool {
return s != ""
}
)
fmt.Println("Or (true):", pHello.Or(pWorld)("hello"))
fmt.Println("Or (false):", pHello.Or(pWorld)("foo"))
fmt.Println("And (false):", pHello.And(pWorld)("hello"))
fmt.Println("And (true):", pHello.And(pAny)("hello"))
fmt.Println("Negate (false):", pHello.Negate()("hello"))
fmt.Println("Negate (true):", pHello.Negate()("world"))
fmt.Println("Chained (true):", pHello.And(pAny.Or(pWorld))("hello"))
fmt.Println("Chained (false):", pHello.And(pAny.Or(pWorld))("foo"))
}
Output: Or (true): true Or (false): false And (false): false And (true): true Negate (false): false Negate (true): true Chained (true): true Chained (false): false
func (P[T]) And ¶
And returns a predicate that is a short-circuiting logical AND of this and the given predicates.
Click to show internal directories.
Click to hide internal directories.