bkietz commented on code in PR #36424:
URL: https://github.com/apache/arrow/pull/36424#discussion_r1254376586


##########
cpp/src/arrow/compute/expression.cc:
##########
@@ -362,8 +362,20 @@ bool Expression::IsSatisfiable() const {
   }
 
   if (call->function_name == "and_kleene" || call->function_name == "and") {
-    for (const Expression& arg : call->arguments) {
-      if (!arg.IsSatisfiable()) return false;
+    bool has_unsatisfiable =
+        std::any_of(call->arguments.begin(), call->arguments.end(),
+                    [](const Expression& arg) { return !arg.IsSatisfiable(); 
});
+    if (has_unsatisfiable) {
+      return false;
+    }
+  }
+
+  if (call->function_name == "or_kleene" || call->function_name == "or") {
+    bool all_unsatisfiable =
+        std::all_of(call->arguments.begin(), call->arguments.end(),
+                    [](const Expression& arg) { return !arg.IsSatisfiable(); 
});
+    if (all_unsatisfiable) {
+      return false;

Review Comment:
   IMO, using the std algorithms in this way is less readable than the for 
loop, please use that instead
   ```suggestion
       for (const Expression& arg : call->arguments) {
         if (!arg.IsSatisfiable()) return false;
       }
       return true;
     }
   
     if (call->function_name == "or_kleene" || call->function_name == "or") {
       for (const Expression& arg : call->arguments) {
         if (arg.IsSatisfiable()) return true;
       }
       return false;
   ```
   
   Or alternatively rewrite to return the result of the std algorithms directly
   ```suggestion
       return std::all_of(call->arguments.begin(), call->arguments.end(),
                          [](const Expression& arg) { return 
arg.IsSatisfiable(); });
     }
   
     if (call->function_name == "or_kleene" || call->function_name == "or") {
       return std::any_of(call->arguments.begin(), call->arguments.end(),
                          [](const Expression& arg) { return 
arg.IsSatisfiable(); });
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to