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

map:build: sequence of keys #236

Closed
ndw opened this issue Nov 11, 2022 · 1 comment
Closed

map:build: sequence of keys #236

ndw opened this issue Nov 11, 2022 · 1 comment
Labels
Completed PR has been applied, tests written and tagged, no further action needed Enhancement A change or improvement to an existing feature Tests Added Tests have been added to the test suites XQFO An issue related to Functions and Operators

Comments

@ndw
Copy link
Contributor

ndw commented Nov 11, 2022

In resolving PR #203 to address issue #151, the group decided not to immediately address all of the concerns raised by Martin Honnen in an email discussion where he wrote:

When map:group-by was introduced I found the restriction of a single key
instead of a sequence of keys unnecessarily restrictive (some people on
Slack agreed), the same appears in my view to be the case for the new
map:build, I think it could be easily adapted to handle a sequence of
keys by using e.g.

  fold-left($input, map{}, ->($map, $next) {

   fold-left($key($next), $map, ->($map, $key) {
    let $nextValue := $value($next) return
    if (map:contains($map, $key))
    then map:put($map, $key, $combine($map($key), $nextValue))
    else map:put($map, $key, $nextValue)})
  }
)

as the implementation body/definition of the result of

map:build(
$input    as item()*,
$key    as function(item()) as xs:anyAtomicType*    := fn:identity#1,
$value    as function(item()) as item()*    := fn:identity#1,
$combine    as function(item()*, item()*) as item()*    := fn:op(',')
) as map(*)


Use case in my view is the classical example of the XSLT 3 spec where in
e.g.

<titles>
     <title>A Beginner's Guide to <ix>Java</ix></title>
     <title>Learning <ix>XML</ix></title>
     <title>Using <ix>XML</ix> with <ix>Java</ix></title>
</titles>

you want to group the "title" elements by the "ix" child elements, with
the proposed change above that would give e.g.

map {
   "Java": (<title>A Beginner's Guide to <ix>Java</ix>
</title>, <title>Using <ix>XML</ix> with <ix>Java</ix>
</title>),
   "XML": (<title>Learning <ix>XML</ix>
</title>, <title>Using <ix>XML</ix> with <ix>Java</ix>
</title>)
}

We'll come back to this later.

Creating this issue satisfies action QT4CG-008-05 on NW.

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Enhancement A change or improvement to an existing feature labels Nov 11, 2022
@ChristianGruen ChristianGruen added the Propose for V4.0 The WG should consider this item critical to 4.0 label Dec 19, 2023
@ChristianGruen ChristianGruen self-assigned this Feb 7, 2024
@ChristianGruen ChristianGruen changed the title map:group-by or map:build with a sequence of keys map:build: sequence of keys Feb 7, 2024
@ChristianGruen
Copy link
Contributor

It’s been a while… I’ll tackle a PR if no one objects.

@ChristianGruen ChristianGruen added Tests Needed Tests need to be written or merged PR Pending A PR has been raised to resolve this issue and removed Propose for V4.0 The WG should consider this item critical to 4.0 labels Feb 23, 2024
@ChristianGruen ChristianGruen removed their assignment Feb 23, 2024
@ndw ndw closed this as completed in 5bc4a4f Feb 27, 2024
@michaelhkay michaelhkay added Tests Added Tests have been added to the test suites Completed PR has been applied, tests written and tagged, no further action needed and removed PR Pending A PR has been raised to resolve this issue Tests Needed Tests need to be written or merged labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Completed PR has been applied, tests written and tagged, no further action needed Enhancement A change or improvement to an existing feature Tests Added Tests have been added to the test suites XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

3 participants