mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-16 09:26:21 -05:00
40 lines
670 B
Go
40 lines
670 B
Go
package predicate // import "v2ray.com/core/common/predicate"
|
|
|
|
type Predicate func() bool
|
|
|
|
func (v Predicate) And(predicate Predicate) Predicate {
|
|
return All(v, predicate)
|
|
}
|
|
|
|
func (v Predicate) Or(predicate Predicate) Predicate {
|
|
return Any(v, 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()
|
|
}
|
|
}
|