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

array:members-at #825

Closed
dnovatchev opened this issue Nov 9, 2023 · 9 comments
Closed

array:members-at #825

dnovatchev opened this issue Nov 9, 2023 · 9 comments
Labels
Feature A change that introduces a new feature Propose Closing with No Action The WG should consider closing this issue with no action XQFO An issue related to Functions and Operators

Comments

@dnovatchev
Copy link
Contributor

dnovatchev commented Nov 9, 2023

The title says it all.

We have fn:slice and array:slice. We also do have fn:items-at, but we have somehow missed to add the corresponding array:items-at array:members-at function.

We could even think of a function map:entries-at and map:values-for-keys. The first of these would return all map entries that have as keys one of the provided as argument set of keys. The 2nd function would return all values of the map entries that have as keys one of the provided as argument set of keys.

Here is a complete XPath 3.1 implementation:

let $members-at := function(
                 $input as array( *), 
                 $indexes as xs:integer*
                ) as array(*)*
 {
     for $ind in $indexes
       return [$input($ind)]
 }

Example:

Evaluating this expression:

let $members-at := function(
                 $input as array( *), 
                 $indexes as xs:integer*
                ) as array(*)*
 {
     for $ind in $indexes
       return [$input($ind)]
 }
  return
     $members-at([1, (2, 3), (4, 5, 6)], (1, 3) )

produces the wanted result:

[1], [(4,5,6)]

@dnovatchev dnovatchev added Bug Something that doesn't work in the current specification XQFO An issue related to Functions and Operators Editorial Minor typos, wording clarifications, example fixes, etc. Feature A change that introduces a new feature labels Nov 9, 2023
@ChristianGruen ChristianGruen removed Bug Something that doesn't work in the current specification Editorial Minor typos, wording clarifications, example fixes, etc. labels Nov 9, 2023
@michaelhkay
Copy link
Contributor

The reason for the omission is that arrays do not contains items, they contain members, which are sequences. Filtering is therefore a more complex operation.

@michaelhkay
Copy link
Contributor

I agree though that array:members-at() would be a useful addition.

@ChristianGruen
Copy link
Contributor

ChristianGruen commented Nov 9, 2023

@dnovatchev I assume you would expect the signature to be…

fn:members-at(
  $array  as array(*),	
  $at     as xs:integer*	
) as array(*)

…and array:join($at ! [ $array(.) ]) would be an equivalent expression?

Related: #135

@dnovatchev
Copy link
Contributor Author

@dnovatchev I assume you would expect the signature to be…

fn:members-at(
  $array  as array(*),	
  $at     as xs:integer*	
) as array(*)

…and array:join($at ! [ $array(.) ]) would be an equivalent expression?

Related: #135

@ChristianGruen I had significant difficulties understanding what this expression was intended to mean.

Why should one spend 30 minutes to decipher what such expression may mean, when they could use a very understandable fn:members-at ?

@dnovatchev
Copy link
Contributor Author

dnovatchev commented Nov 9, 2023

I agree though that array:members-at() would be a useful addition.

Absolutely agree!

I will edit the title and the issue.

Done!

@dnovatchev dnovatchev changed the title FO: Missing function array:items-at FO: Missing function array:members-at Nov 9, 2023
@ChristianGruen
Copy link
Contributor

Why should one spend 30 minutes to decipher what such expression may mean, when they could use a very understandable fn:members-at ?

No need to. Once again, this seems to be a misunderstanding. I just wanted to understand what exactly your function is expected to do, as it needs to be implemented at some stage. Feel free to add a better explanation.

@dnovatchev
Copy link
Contributor Author

dnovatchev commented Nov 9, 2023

Why should one spend 30 minutes to decipher what such expression may mean, when they could use a very understandable fn:members-at ?

No need to. Once again, this seems to be a misunderstanding. I just wanted to understand what exactly your function is expected to do, as it needs to be implemented at some stage. Feel free to add a better explanation.

A proposal for array:members-at will essentially be similar to the one for fn:items-at, where "sequence" is replaced by "array" and "item" by member (in the text) or item()* in the signature.

Writing such a proposal can be done rather mechanically.

I added a complete XPath 3.1 implementation.

@ChristianGruen ChristianGruen changed the title FO: Missing function array:members-at array:members-at Nov 18, 2023
@ChristianGruen
Copy link
Contributor

As we already have array:get, we could possiby drop array:members-at and adjust fn:items-at instead (see #872).

@ChristianGruen ChristianGruen added the Propose Closing with No Action The WG should consider closing this issue with no action label Feb 23, 2024
@ndw
Copy link
Contributor

ndw commented Feb 27, 2024

The CG decided to close this issue without further action at meeting 067.

@ndw ndw closed this as completed Mar 12, 2024
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 Propose Closing with No Action The WG should consider closing this issue with no action XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

4 participants