mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
fn: add predicate combinators for && and ||
This commit is contained in:
parent
a2266c6c73
commit
cd3c17e1c0
1 changed files with 20 additions and 0 deletions
20
fn/predicate.go
Normal file
20
fn/predicate.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package fn
|
||||
|
||||
// Pred[A] is a type alias for a predicate operating over type A.
|
||||
type Pred[A any] func(A) bool
|
||||
|
||||
// PredAnd is a lifted version of the && operation that operates over functions
|
||||
// producing a boolean value from some type A.
|
||||
func PredAnd[A any](p0 Pred[A], p1 Pred[A]) Pred[A] {
|
||||
return func(a A) bool {
|
||||
return p0(a) && p1(a)
|
||||
}
|
||||
}
|
||||
|
||||
// PredOr is a lifted version of the || operation that operates over functions
|
||||
// producing a boolean value from some type A.
|
||||
func PredOr[A any](p0 Pred[A], p1 Pred[A]) Pred[A] {
|
||||
return func(a A) bool {
|
||||
return p0(a) || p1(a)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue