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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ordered Maps: maps that retain insertion order
2 participants