mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-25 00:36:54 +02:00
26 lines
631 B
Go
26 lines
631 B
Go
![]() |
package predicate
|
||
|
|
||
|
func Not[A any](predicate func(A) bool) func(A) bool {
|
||
|
return func(a A) bool {
|
||
|
return !predicate((a))
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// And creates a predicate that combines other predicates via &&
|
||
|
func And[A any](second func(A) bool) func(func(A) bool) func(A) bool {
|
||
|
return func(first func(A) bool) func(A) bool {
|
||
|
return func(a A) bool {
|
||
|
return first(a) && second(a)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Or creates a predicate that combines other predicates via ||
|
||
|
func Or[A any](second func(A) bool) func(func(A) bool) func(A) bool {
|
||
|
return func(first func(A) bool) func(A) bool {
|
||
|
return func(a A) bool {
|
||
|
return first(a) || second(a)
|
||
|
}
|
||
|
}
|
||
|
}
|