Skip to content

Add variadic majority predicate combinator #693

Description

@Seddryck

Summary

Add a variadic majority predicate combinator.

majority(p1, p2, p3, ...)

The same input is evaluated against each supplied predicate. The result is true when strictly more than half of the predicates are satisfied.

Semantics

For n predicates, majority succeeds when more than n / 2 predicates succeed.

Examples:

  • 1 predicate → 1 success required
  • 2 predicates → 2 successes required
  • 3 predicates → 2 successes required
  • 4 predicates → 3 successes required
  • 5 predicates → 3 successes required

Requirements

  • Accept any number of predicate arguments.
  • Evaluate every predicate against the same input value.
  • Short-circuit as soon as the final result is known.
  • Define and test behavior for zero predicate arguments.
  • Add conformance tests and function metadata/documentation.

Notes

majority is intentionally a named logical concept rather than a special case of the predicate-cardinality functions. Its threshold depends on the number of supplied predicates and is therefore useful enough to express directly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic-on-predicatesFeatures and enhancements about boolean functionsnew-featureRequest for a new feature in the tool

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions