-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Expression.asBoolean() #15547
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
base: feat/pipeline/private-preview
Are you sure you want to change the base?
Add Expression.asBoolean() #15547
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
Generated by 🚫 Danger |
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a significant and beneficial refactoring by changing BooleanExpression from a class to a protocol, which is more idiomatic in Swift. The new Expression.asBoolean() method provides a clean and type-safe way to perform conversions. The changes are well-implemented and include corresponding test updates. I have a couple of suggestions to enhance the code further, mainly regarding code style and ensuring the public API remains consistent.
...store/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpression.swift
Show resolved
Hide resolved
...store/Swift/Source/SwiftAPI/Pipeline/Expressions/FunctionExpressions/BooleanExpression.swift
Show resolved
Hide resolved
| func asBoolean() -> BooleanExpression { | ||
| if let boolExpr = self as? BooleanExpression { | ||
| return boolExpr | ||
| } | ||
| if let constant = self as? Constant { | ||
| return BooleanConstant(constant) | ||
| } | ||
| if let field = self as? Field { | ||
| return BooleanField(field) | ||
| } | ||
| if let funcExpr = self as? FunctionExpression { | ||
| return BooleanFunctionExpression(funcExpr) | ||
| } | ||
| // This should be unreachable if all expression types are handled. | ||
| fatalError( | ||
| "Unknown expression type \(Swift.type(of: self)) cannot be converted to BooleanExpression" | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability and to follow Swift idioms, consider using a switch statement here instead of a chain of if-let statements. A switch statement makes the different cases clearer and is often more efficient for type casting.
func asBoolean() -> BooleanExpression {
switch self {
case let boolExpr as BooleanExpression:
return boolExpr
case let constant as Constant:
return BooleanConstant(constant)
case let field as Field:
return BooleanField(field)
case let funcExpr as FunctionExpression:
return BooleanFunctionExpression(funcExpr)
default:
// This should be unreachable if all expression types are handled.
fatalError(
"Unknown expression type \(Swift.type(of: self)) cannot be converted to BooleanExpression"
)
}
}…xpressions/BooleanExpression.swift Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…xpressions/BooleanExpression.swift Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Compared with the Android SDK implementation (reference: the linked commit), Android provides static functions such as
Expression.rawFunctionandBooleanExpression.rawFunctionto create raw expressions. In the iOS SDK, bothExpressionandBooleanExpressionare protocols, and we prefer not to introduce additional static factory methods. Instead, both use cases are covered by the FunctionExpression() constructor, which provides equivalent functionality without adding static APIs.