Skip to content

[Issue]: [Feature] pred(callable) — predicate pattern #14

Description

@sentomk

Issue Type

Feature Proposal

Description

Lift an arbitrary unary predicate into a first-class pattern, evaluated during the match phase rather than as a post-bind guard.

match(x) | on(
  pred([](int v) { return v % 2 == 0; }) >> "even",
  _ >> "odd"
);

Rationale / Motivation

Currently, evaluating a predicate requires a post-bind guard (e.g., using PTN_WHERE or operator []). A first-class predicate pattern reads more naturally and allows the matching engine to evaluate the condition earlier in the pipeline. It also enables native composition within combinators like any(...) or all(...) without requiring intermediate bindings. This is tracked under the WIP section of the roadmap.md.

Alternatives Considered

Using standard guards (pattern[guard]), but pred(...) offers better ergonomics for simple unary callables and integrates seamlessly with other pattern combinators.

Checklist

  • I have searched existing issues and discussions
  • This issue aligns with Patternia’s design goals

Activity

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

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions