Summary
Add a family of predicate-cardinality combinators:
satisfies-exactly(count, p1, p2, ...)
satisfies-at-least(count, p1, p2, ...)
satisfies-at-most(count, p1, p2, ...)
Each predicate is evaluated against the same input value. The functions return a boolean according to how many supplied predicates are satisfied.
Semantics
satisfies-exactly(n, ...) returns true iff exactly n predicates are satisfied.
satisfies-at-least(n, ...) returns true iff at least n predicates are satisfied.
satisfies-at-most(n, ...) returns true iff at most n predicates are satisfied.
count must be a non-negative integer.
Short-circuiting
The functions should stop evaluating predicates as soon as the final result is known.
Examples:
satisfies-at-least(2, ...) can return true after the second satisfied predicate.
satisfies-at-most(2, ...) can return false after the third satisfied predicate.
satisfies-exactly(2, ...) can return false after the third satisfied predicate, or when too few predicates remain to reach two.
Relationship with existing logical combinators
These functions generalize several common logical concepts:
any(...) is equivalent to satisfies-at-least(1, ...).
none(...) is equivalent to satisfies-exactly(0, ...).
- an
exactly-one(...) helper would merely be satisfies-exactly(1, ...), so no separate primitive is required.
all(...) remains a useful named logical concept because its target cardinality depends on the number of supplied predicates.
majority(...) remains a separate named combinator because its threshold also depends on the number of supplied predicates.
Requirements
- Accept any number of predicate arguments after
count.
- Evaluate all predicate arguments against the same input value.
- Validate the
count argument.
- Define behavior when no predicate arguments are supplied.
- Implement short-circuit evaluation.
- Add conformance tests and function metadata/documentation.
Summary
Add a family of predicate-cardinality combinators:
Each predicate is evaluated against the same input value. The functions return a boolean according to how many supplied predicates are satisfied.
Semantics
satisfies-exactly(n, ...)returnstrueiff exactlynpredicates are satisfied.satisfies-at-least(n, ...)returnstrueiff at leastnpredicates are satisfied.satisfies-at-most(n, ...)returnstrueiff at mostnpredicates are satisfied.countmust be a non-negative integer.Short-circuiting
The functions should stop evaluating predicates as soon as the final result is known.
Examples:
satisfies-at-least(2, ...)can returntrueafter the second satisfied predicate.satisfies-at-most(2, ...)can returnfalseafter the third satisfied predicate.satisfies-exactly(2, ...)can returnfalseafter the third satisfied predicate, or when too few predicates remain to reach two.Relationship with existing logical combinators
These functions generalize several common logical concepts:
any(...)is equivalent tosatisfies-at-least(1, ...).none(...)is equivalent tosatisfies-exactly(0, ...).exactly-one(...)helper would merely besatisfies-exactly(1, ...), so no separate primitive is required.all(...)remains a useful named logical concept because its target cardinality depends on the number of supplied predicates.majority(...)remains a separate named combinator because its threshold also depends on the number of supplied predicates.Requirements
count.countargument.