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

1651 ordered maps #1703

Merged
merged 18 commits into from
Jan 22, 2025
Merged

1651 ordered maps #1703

merged 18 commits into from
Jan 22, 2025

Conversation

michaelhkay
Copy link
Contributor

@michaelhkay michaelhkay commented Jan 14, 2025

Reopened pull request introducing ordered maps.

Fix #1651.

Copy link
Contributor

@ChristianGruen ChristianGruen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the proposal, including the definition of “entry order”, and I appreciate the effort made to incorporate all the changes.

and returns the sequence concenation of the results.</p>
<p>The <code>dm:iterate-map</code> accessor calls the supplied <code>$action</code>
function once for each key/value pair in <code>$map</code>,
and returns the sequence concenation of the results. The order in which entries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and returns the sequence concenation of the results. The order in which entries
and returns the sequence concatenation of the results. The order in which entries

<!--<fos:option key="retain-order">
<fos:meaning>Determines the
<xtermref spec="DM40" ref="dt-entry-order">entry order</xtermref> of the
entries in the returned map, as well as the value of the map's
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entries in the returned map, as well as the value of the map's
entries in the returned map, as well as the value of the maps

@@ -23105,7 +23129,7 @@ let $combine := fn($A as map(*), $B as map(*), $deduplicator as fn(*)) {
else map:put($z, $k, $B($k))
})
}
return fold-left($maps, {},
return fold-left($maps, dm:empty-map($options?ordering otherwise "undefined"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fold-left($maps, dm:empty-map($options?ordering otherwise "undefined"),
return fold-left($maps, {},

@@ -23217,6 +23243,12 @@ return fold-left($maps, {},
entry that appears in the result is the <xtermref spec="XP40" ref="dt-sequence-concatenation">sequence concatenation</xtermref> of the entries
in the input maps, retaining order.</fos:postamble>
</fos:test>

<fos:test>
<fos:expression><eg>map:merge(({ "red": 0 }, { "green": 1}, { "blue": 2 }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<fos:expression><eg>map:merge(({ "red": 0 }, { "green": 1}, { "blue": 2 }),
<fos:expression><eg>map:merge(({ "red": 0 }, { "green": 1}, { "blue": 2 }))


<fos:test>
<fos:expression><eg>map:merge(({ "red": 0 }, { "green": 1}, { "blue": 2 }),
{ "retain-order": true() } => map:keys()</eg></fos:expression>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ "retain-order": true() } => map:keys()</eg></fos:expression>
=> map:keys()</eg></fos:expression>

};
</eg>

<p>So the call <code>cx:complex(3, 2)</code> produces the value <code>{ "r": 3e0, "i": 2e0 }</code>,
while the call <code>cx:complex(3)</code> produces the value <code>{ "r": 3e0, "i": 0e0 }</code></p>

<p>The resulting map has its <xtermref spec="DM40" ref="dt-map-ordered"/> property set to
<code>true</code>, so the order of entries corresponds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<code>true</code>, so the order of entries corresponds
<p>The order of entries corresponds

@@ -2157,7 +2163,7 @@ local:depth(doc("partlist.xml"))
map:merge((
{ "r": $r },
if (exists($i)) { { "i": $i } }
))
), { "retain-order" : true() })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
), { "retain-order" : true() })
))

@@ -2186,13 +2192,16 @@ local:depth(doc("partlist.xml"))
{ "last": $last },
$options
),
{ "duplicates": "use-first" }
{ "duplicates": "use-first", "retain-order" : true() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{ "duplicates": "use-first", "retain-order" : true() }
{ "duplicates": "use-first" }

};
</eg>

<p>The effect of the <code>duplicates</code> option here is that when two values are supplied for the same field,
one as a direct argument in the function call and the other in the <code>options</code> map, the value supplied
as a direct argument is used in preference.</p>
as a direct argument is used in preference. The effect of the <code>ordering</code> option is that the resulting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
as a direct argument is used in preference. The effect of the <code>ordering</code> option is that the resulting
as a direct argument is used in preference. The resulting

@@ -2242,8 +2251,7 @@ local:depth(doc("partlist.xml"))
<item><p>The optional final subexpression, if present, takes the form <code>$options</code>,
where <code>$options</code> is the name allocated to the final parameter.</p></item>
<item><p>The second argument in the call of the function <code>map:merge</code>
is the map <code>{ "duplicates": "use-first" }</code>. This can be omitted if the record is not
extensible, because in this case duplicate field names cannot arise.</p></item>
is the map <code>{ "duplicates": "use-first", "retain-order": true() }</code>.</p></item>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is the map <code>{ "duplicates": "use-first", "retain-order": true() }</code>.</p></item>
is the map <code>{ "duplicates": "use-first" }</code>.</p></item>

@ChristianGruen ChristianGruen changed the title 1609 ordered maps 1651 ordered maps Jan 16, 2025
@michaelhkay michaelhkay added XPath An issue related to XPath XQuery An issue related to XQuery XSLT An issue related to XSLT XQFO An issue related to Functions and Operators XDM An issue related to the XPath Data Model Feature A change that introduces a new feature Tests Needed Tests need to be written or merged labels Jan 21, 2025
@michaelhkay
Copy link
Contributor Author

I have applied all the copy-edits suggested by Christian.

@michaelhkay michaelhkay merged commit c2fa683 into qt4cg:master Jan 22, 2025
3 checks passed
@ChristianGruen
Copy link
Contributor

…looks all good!

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 Tests Needed Tests need to be written or merged XDM An issue related to the XPath Data Model XPath An issue related to XPath XQFO An issue related to Functions and Operators XQuery An issue related to XQuery XSLT An issue related to XSLT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ordered Maps: maps that retain insertion order
2 participants