-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement array expressions #1043
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import java.util.function.BinaryOperator; | ||
import java.util.function.Function; | ||
|
||
import static com.mongodb.client.model.expressions.Expressions.of; | ||
|
||
/** | ||
* Expresses an array value. An array value is a finite, ordered collection of | ||
* elements of a certain type. | ||
|
@@ -61,4 +63,29 @@ public interface ArrayExpression<T extends Expression> extends Expression { | |
*/ | ||
T reduce(T initialValue, BinaryOperator<T> in); | ||
|
||
IntegerExpression size(); | ||
|
||
T elementAt(IntegerExpression i); | ||
|
||
default T elementAt(final int i) { | ||
return this.elementAt(of(i)); | ||
} | ||
|
||
T first(); | ||
|
||
T last(); | ||
|
||
BooleanExpression contains(T contains); | ||
|
||
ArrayExpression<T> concat(ArrayExpression<T> array); | ||
|
||
ArrayExpression<T> slice(IntegerExpression start, IntegerExpression length); | ||
|
||
default ArrayExpression<T> slice(final int start, final int length) { | ||
return this.slice(of(start), of(length)); | ||
} | ||
|
||
ArrayExpression<T> union(ArrayExpression<T> set); | ||
|
||
ArrayExpression<T> distinct(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps union should exclude The name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we look at SQL, what we call If you don't see a way to simply and clearly express the lack of order in the names, it's fine, neither do I. As for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed that this does not preserve order even when there is only one set in the union:
passes. I agree that given what you say, distinct will imply they remain in the same order for users familiar with SQL distinct. And even the streams distinct specifies that if it is ordered, it will remain ordered. But the two other points (setField is weird, implies other type) still seem compelling. Maybe some variation of "unique" instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with |
||
} |
Uh oh!
There was an error while loading. Please reload this page.