Skip to content

add any and all helper functions#12

Merged
mendelt merged 1 commit intomainfrom
any_all
Dec 17, 2025
Merged

add any and all helper functions#12
mendelt merged 1 commit intomainfrom
any_all

Conversation

@mendelt
Copy link
Copy Markdown
Owner

@mendelt mendelt commented Dec 15, 2025

No description provided.

@mendelt mendelt requested a review from Copilot December 15, 2025 20:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds two new helper functions any and all to the expression language, which evaluate whether any or all items in a list are true. The implementation includes:

  • Parser support for the new any and all keywords
  • Expression enum variants and evaluation logic for both functions
  • Comprehensive test coverage including standalone tests and integration with existing for map functionality

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/for_map_filter.rs Adds test cases for any, all, nested for operations, and their combinations
src/reval.lalrpop Registers any and all as keywords and adds parser rules for function calls
src/expr/mod.rs Defines Any and All expression variants and their Display implementations
src/expr/keywords.rs Adds "any" and "all" to the reserved keywords list
src/expr/eval/mod.rs Implements evaluation logic for any and all functions
src/expr/constructor.rs Adds constructor methods for creating Any and All expressions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +663 to +667
for item in vec {
match item {
Value::Bool(true) => return Ok(Value::Bool(true)),
Value::Bool(false) => continue,
_ => return Err(Error::InvalidType),
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The any function silently ignores non-boolean values in the vector. If a vector contains non-boolean items (like integers, strings, etc.), they are treated as false which may lead to incorrect results. Consider validating that all items in the vector are booleans and returning an error for non-boolean values, similar to how other type-strict functions in the codebase (like not) handle invalid types.

Copilot uses AI. Check for mistakes.
Comment on lines +678 to +682
match value {
Value::Vec(vec) => {
for item in vec {
match item {
Value::Bool(true) => continue,
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The all function silently ignores non-boolean values in the vector. If a vector contains non-boolean items, they are treated as true which may lead to incorrect results. For example, all([true, "string", true]) would return true even though "string" is not a boolean. Consider validating that all items in the vector are booleans and returning an error for non-boolean values, similar to how other type-strict functions in the codebase (like not) handle invalid types.

Copilot uses AI. Check for mistakes.
Comment on lines +44 to +53
async fn should_evaluate_any() {
assert_eq!(
eval_expr("any([false, false, true, false])", ()).await,
true.into()
);
assert_eq!(
eval_expr("any([false, false, false])", ()).await,
false.into()
);
}
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The test coverage for the any function is missing important edge cases. Consider adding tests for: 1) an empty array (should return false), 2) an array with Value::None (to verify None handling), and 3) an array with non-boolean values (to verify type validation behavior).

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +62
async fn should_evaluate_all() {
assert_eq!(eval_expr("all([true, true, true])", ()).await, true.into());
assert_eq!(
eval_expr("all([true, false, true])", ()).await,
false.into()
);
}
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The test coverage for the all function is missing important edge cases. Consider adding tests for: 1) an empty array (should return true by convention in most languages), 2) an array with Value::None (to verify None handling), and 3) an array with non-boolean values (to verify type validation behavior).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@discosultan discosultan left a comment

Choose a reason for hiding this comment

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

LGTM

Can confirm that after this change, the original use case which started all this is finally working.

@mendelt mendelt merged commit ba25b69 into main Dec 17, 2025
25 checks passed
@mendelt mendelt deleted the any_all branch December 17, 2025 16:07
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.

3 participants