<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29353</bug_id>
          
          <creation_ts>2015-12-30 18:09:11 +0000</creation_ts>
          <short_desc>Lossless map:merge</short_desc>
          <delta_ts>2016-09-26 05:11:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3.2 Use Cases and Requirements</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>rxk2rxk</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>abel.braaksma</cc>
    
    <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>124494</commentid>
    <comment_count>0</comment_count>
    <who name="">rxk2rxk</who>
    <bug_when>2015-12-30 18:09:11 +0000</bug_when>
    <thetext>Hi,

I am using map:merge to construct a map from smaller maps and would like to preserve values when the keys agree. For example, when calling

    map:merge((map:entry(0, &quot;red&quot;), (map:entry(1, &quot;green&quot;), map:entry(1, &quot;blue&quot;)))

I would like to get back something like

    map { 0: &quot;red&quot;, 1: (&quot;green&quot;, &quot;blue&quot;) }

The W3C specification is to drop &quot;green&quot; in favor of &quot;blue&quot;.

While the desired behavior can be accomplished using XQuery syntax, the solution is not elegant and is relatively slow. Would it be possible to add an option to map:merge that will exhibit lossless merging?

Thanks,
Ron</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124498</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-12-31 08:22:49 +0000</bug_when>
    <thetext>Your desired function can be written

function f:merge-entries($m1, $m2) {
  map:merge(
    for $k in distinct-values((map:keys($m1), map:keys($m2))
    return map{$k : ($m1($k), $m2($k))}
  )
}

which doesn&apos;t feel inelegant to me, and if it&apos;s inefficient, that&apos;s an implementation problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124500</commentid>
    <comment_count>2</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2015-12-31 15:28:18 +0000</bug_when>
    <thetext>I would agree that it&apos;d be nice to have a map:merge that can do that. 

I.e., perhaps one that takes a second argument that is a higher order function which takes a sequence of map entries that contain the same key. However, writing such a function is trivial (Michael shows one approach, which can be made higher-order), which you can then use as a generic variant of map:merge.

I doubt that, considering the spec is in CR stage, new functions, or variants of functions can be added.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124501</commentid>
    <comment_count>3</comment_count>
    <who name="Abel Braaksma">abel.braaksma</who>
    <bug_when>2016-01-01 12:33:52 +0000</bug_when>
    <thetext>&gt; I doubt that, considering the spec is in CR stage, new functions, or 
&gt; variants of functions can be added.
Apologies, I see now that this was raised against XQ 3.2 Use Cases.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124503</commentid>
    <comment_count>4</comment_count>
    <who name="">rxk2rxk</who>
    <bug_when>2016-01-01 22:09:09 +0000</bug_when>
    <thetext>Ok. But it gets more complicated if the merge is done repeatedly in a loop over a large database (e.g., 200,000 clinical trials). Adding an option in Java should be straightforward and the most efficient solution IMHO. Otherwise, feel free to close this suggestion.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127528</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-09-26 05:11:15 +0000</bug_when>
    <thetext>This can now be done in 3.1 using the syntax

map:merge($maps, map{&quot;duplicates&quot;:&quot;combine&quot;})</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>