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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions specifications/xpath-datamodel-40/src/xpath-datamodel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ therefore can also be contained within sequences.</p>

<p>The <code>dm:iterate-sequence</code> accessor calls the supplied <code>$action</code>
function once for each item in <code>$input</code>, in order,
and returns the sequence concenation of the results. The <code>$action</code> function
and returns the sequence concatenation of the results. The <code>$action</code> function
is called with two arguments. The first argument is an item in <code>$input</code>,
and the second is the 1-based ordinal position of the item within <code>$input</code>.</p>

Expand Down Expand Up @@ -1511,40 +1511,49 @@ must equal the function’s arity.
<changes>
<change issue="1335" date="2024-07-20">Constructors are added, and the single accessor function
is now an iterator over the key/value pairs in the map.</change>
<change issue="1651" PR="1703" date="2025-01-14">Ordered maps are introduced.</change>
</changes>

<p><termdef term="map item" id="dt-map-item">A <term>map item</term>
is a value that represents a map (in other languages this is sometimes
called a hash, dictionary, or associative array).</termdef>
A map is logically a collection of
key/value pairs. Each key in the map is unique (there is no other key
to which it is equal) and has associated with it a value that is a sequence
is an item that represents an ordered sequence of key/value pairs,
in which the keys are unique.</termdef>
In other languages this is sometimes
called a hash, dictionary, or associative array.
The keys are atomic items, and each key in the map is unique (there is no other key
to which it is equal). Each key is associated with a value that may be any sequence
of zero or more items. There is no uniqueness constraint on
values. The semantics of equality are described in
values, only on keys. The semantics of equality when comparing keys are described in
<xspecref spec="FO40" ref="func-atomic-equal"/>.</p>



<note>

<note>
<p>Maps have no intrinsic identity separate from their content. A map can be given
a transient identity, represented by an <code>id</code> property in its label, by applying the
<code>fn:pin</code> function. This property is expected to be used in defining
operations for deep update of maps.
</p>
</note>



<p><termdef id="dt-entry-order" term="entry order">The order of entries in a map
is referred to as <term>entry order</term>.</termdef>
The entry order affects the result of functions such as <function>map:keys</function>
and <function>map:for-each</function>, and also determines the order of entries
when a map is serialized using the JSON output method.</p>


<p>Constructor and accessor functions for maps are defined in the following sections.</p>

<div4 id="dm-empty-map">
<head><code>empty-map</code> Constructor</head>
<example role="signature">
<proto class="dm" name="empty-map" return-type="map(*)" returnSeq="no"/>
<proto class="dm" name="empty-map" return-type="map(*)" returnSeq="no"/>
</example>

<p>The <code>dm:empty-map</code> constructor returns a map containing no key/value pairs.</p>

<p>The function is exposed in XPath as an empty map constructor, which may be written <code>{}</code>
or <code>map {}</code>.</p>
<note><p>In XPath an empty map may be constructed using the expression <code>{}</code>
or <code>map {}</code>.</p></note>
</div4>

<div4 id="dm-map-put">
Expand All @@ -1565,7 +1574,13 @@ values. The semantics of equality are described in
<item><p>One key/value pair whose key is <code>$key</code> and whose associated value is <code>$value</code>.</p></item>
</ulist>

<p>The function is exposed in XPath through the function <code>map:put</code>.</p>

<p>The <termref def="dt-entry-order"/> in the returned
map reflects the <termref def="dt-entry-order"/> in the supplied <code>$map</code>. If the key of
the new entry was present in <code>$map</code> then the new entry replaces that entry retaining
its current position; otherwise, the new entry is added after all existing entries.</p>

<p>The function is exposed in XPath through the function <function>map:put</function>.</p>
</div4>

<div4 id="dm-iterate-map">
Expand All @@ -1578,13 +1593,14 @@ values. The semantics of equality are described in
</proto>
</example>

<p>The <function>dm:iterate-map</function> accessor calls the supplied <code>$action</code>
function once for each key/value pair in <code>$map</code>, in implementation-dependent order,
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

are processed is the <termref def="dt-entry-order"/> of the map.</p>

<p>The function is exposed in XPath most directly through the function <code>map:for-each</code>, but
it also underpins all other functions giving access to maps, such as <code>map:size</code>,
<code>map:contains</code>, and <code>map:get</code>.</p>
<p>The function is exposed in XPath most directly through the function <function>map:for-each</function>, but
it also underpins all other functions giving access to maps, such as <function>map:size</function>,
<function>map:contains</function>, and <function>map:get</function>.</p>

</div4>

Expand Down
Loading
Loading