Skip to content

Initializers for joining a sequence of predicates#1878

Open
MatthewTurk247 wants to merge 1 commit intoswiftlang:mainfrom
MatthewTurk247:initializers-join-predicates
Open

Initializers for joining a sequence of predicates#1878
MatthewTurk247 wants to merge 1 commit intoswiftlang:mainfrom
MatthewTurk247:initializers-join-predicates

Conversation

@MatthewTurk247
Copy link
Copy Markdown
Contributor

This pull request implements the initializers proposed in #1860.

Testing:

See PredicateTests/all() and PredicateTests/any().

@MatthewTurk247 MatthewTurk247 requested a review from a team as a code owner April 4, 2026 02:53
}

@Test func all() throws {
#expect(try Predicate(all: []).evaluate(42))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually a bit surprised this compiles without telling it what the Input type of the predicate is here. Does it infer an input of type Int from the call to evaluate using the type of 42?

#expect(try !Predicate(all: predicates).evaluate(input))
predicates.append(#Predicate { $0.c < 0.0 })
#expect(try !Predicate(all: predicates).evaluate(input))
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add tests that validate the short circuiting behavior to validate that predicates later in the list aren't evaluated if a prior expression fails? This should be possible with a custom object and a property (referenced in the predicate via a keypath) that records when the property is accessed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants