Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Clarify use of infallable APIs #13217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Nov 1, 2024

Which issue does this PR close?

Follow on ot

Rationale for this change

Implement @findepi 's suggestion in #13206 (comment)

#13206 (comment)

What changes are included in this PR?

Make the uses of exists with an infallable closure (aka never returns Err) clear

Are these changes tested?

By CI

Are there any user-facing changes?

No

@github-actions github-actions bot added the logical-expr Logical plan and expressions label Nov 1, 2024
@@ -1554,13 +1554,13 @@ impl Expr {
/// Returns true if there are any column references in this Expr
pub fn any_column_refs(&self) -> bool {
self.exists(|expr| Ok(matches!(expr, Expr::Column(_))))
.unwrap()
.expect("exists closure is infallible")
Copy link
Member

Choose a reason for hiding this comment

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

It's fine, but would it be possible to make .exists not return Result at all when closure doesn't return it?

would doing Try same way as iter.try_fold does work here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose we could rename exists to try_exists and then switch exists to not be fallable 🤔

Copy link
Member

Choose a reason for hiding this comment

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

i tried to model this in a generic way with something like

F: Fn -> R
R: MaybeFallible<bool>
```

```
trait MaybeFallible<T> {
 fn is_falure(&self) -> bool;
 fn as_value(&self) -> Option<&T>;
```

It's sufficient to model the `exists` function signature generically, but i couldn't get exist and apply both working (perhaps didn't try long enough)

@alamb alamb added the documentation Improvements or additions to documentation label Nov 3, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants