1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-08 14:42:27 +08:00

Add functional nor predicate (#172)

This commit is contained in:
donutloop
2024-02-21 03:05:54 +01:00
committed by GitHub
parent c88fd3db86
commit cd156dba5f
2 changed files with 36 additions and 0 deletions

View File

@@ -32,3 +32,16 @@ func Or[T any](predicates ...func(T) bool) func(T) bool {
return false // False if all predicates are false
}
}
// Nor returns a composed predicate that represents the logical NOR of a list of predicates.
// It evaluates to true only if all predicates evaluate to false for the given value.
func Nor[T any](predicates ...func(T) bool) func(T) bool {
return func(value T) bool {
for _, predicate := range predicates {
if predicate(value) {
return false // If any predicate evaluates to true, the NOR result is false
}
}
return true // Only returns true if all predicates evaluate to false
}
}