1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 01:17:30 -05:00
v2fly/common/predicate/predicate.go
2016-10-11 12:44:17 +02:00

40 lines
638 B
Go

package predicate
type Predicate func() bool
func (this Predicate) And(predicate Predicate) Predicate {
return All(this, predicate)
}
func (this Predicate) Or(predicate Predicate) Predicate {
return Any(this, predicate)
}
func All(predicates ...Predicate) Predicate {
return func() bool {
for _, p := range predicates {
if !p() {
return false
}
}
return true
}
}
func Any(predicates ...Predicate) Predicate {
return func() bool {
for _, p := range predicates {
if p() {
return true
}
}
return false
}
}
func Not(predicate Predicate) Predicate {
return func() bool {
return !predicate()
}
}