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

Filter operator for arrays #1159

Closed
michaelhkay opened this issue Apr 15, 2024 · 2 comments
Closed

Filter operator for arrays #1159

michaelhkay opened this issue Apr 15, 2024 · 2 comments
Labels
Feature A change that introduces a new feature PR Pending A PR has been raised to resolve this issue XPath An issue related to XPath

Comments

@michaelhkay
Copy link
Contributor

michaelhkay commented Apr 15, 2024

I propose to provide ?[...] as a filter operator for arrays.

For example,

let $array := [(1,2,3), (4,5,6,7)]
return $array?[count(.) = 4]

returns

[(4,5,6,7)]

I propose that the operator should work exactly like the familiar [] for sequences in its handling of numeric and boolean predicate values. So for example $array?[2,1] in the above example returns [(4,5,6,7), (1,2,3)]. The result is always an array (which may be a little surprising). This means that $array?[3] has the same effect as [$array?3] or [$array(3)].

@michaelhkay
Copy link
Contributor Author

We could also use this syntax for filtering maps, with the convention that "." is bound to a KVP representing the map entry. So, for example

let $map := {"x1":1, "y":200, "x3":50}
return $map?[?key => starts-with('x') and ?value > 3]

returns {"x3":50}

@ChristianGruen ChristianGruen added XPath An issue related to XPath Feature A change that introduces a new feature labels Apr 16, 2024
@michaelhkay michaelhkay added the PR Pending A PR has been raised to resolve this issue label Apr 19, 2024
@michaelhkay
Copy link
Contributor Author

Closed by acceptance of PR #1163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A change that introduces a new feature PR Pending A PR has been raised to resolve this issue XPath An issue related to XPath
Projects
None yet
Development

No branches or pull requests

2 participants