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

1672 array:values, map:values: Alternatives #1687

Merged
merged 2 commits into from
Jan 14, 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
34 changes: 17 additions & 17 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23492,9 +23492,9 @@ return map:keys-where($birthdays, fn($name, $date) {
</fos:changes>
</fos:function>

<fos:function name="values" prefix="map">
<fos:function name="items" prefix="map">
<fos:signatures>
<fos:proto name="values" return-type="item()*">
<fos:proto name="items" return-type="item()*">
<fos:arg name="map" type="map(*)" usage="inspection"/>
</fos:proto>
</fos:signatures>
Expand All @@ -23507,7 +23507,7 @@ return map:keys-where($birthdays, fn($name, $date) {
<p>Returns a sequence containing all the values present in a map, in unpredictable order.</p>
</fos:summary>
<fos:rules>
<p>The function <function>map:values</function> takes any <termref def="dt-map"
<p>The function <function>map:items</function> takes any <termref def="dt-map"
>map</termref>
as its <code>$map</code> argument and returns the values that are present in the map as
a sequence, in <termref
Expand All @@ -23525,13 +23525,13 @@ return map:keys-where($birthdays, fn($name, $date) {
<fos:examples>
<fos:example>
<fos:test>
<fos:expression><eg>map:values({ 1: "yes", 2: "no" })</eg></fos:expression>
<fos:expression><eg>map:items({ 1: "yes", 2: "no" })</eg></fos:expression>
<fos:result allow-permutation="true">("yes", "no")</fos:result>
<fos:postamble>The result is in <termref def="implementation-dependent"
>implementation-dependent</termref> order.</fos:postamble>
</fos:test>
<fos:test>
<fos:expression><eg>map:values({
<fos:expression><eg>map:items({
1: ("red", "green"),
2: ("blue", "yellow"),
3: ()
Expand Down Expand Up @@ -23779,7 +23779,7 @@ let $entry := dm:iterate-map($map, fn($k, $v) {
})
return (
if (exists($entry))
then map:values($entry)
then map:items($entry)
else $fallback($key)
)
</fos:equivalent>
Expand Down Expand Up @@ -29473,7 +29473,7 @@ return deep-equal(
</fos:rules>
<fos:equivalent style="xpath-expression">
array:for-each($array, fn($member) { [] => array:append($member) })
=> array:values()
=> array:items()
</fos:equivalent>
<fos:notes>
<p>The function call <code>array:split($array)</code> produces the same result as the
Expand Down Expand Up @@ -29747,7 +29747,7 @@ declare function flatten(
$input as item()*
) as item()* {
for $item in $input
return if ($item instance of array(*)) then flatten(array:values($item)) else $item
return if ($item instance of array(*)) then flatten(array:items($item)) else $item
};]]></eg>-->
</fos:rules>
<fos:equivalent style="xquery-function"><![CDATA[
Expand All @@ -29757,7 +29757,7 @@ declare function array:flatten(
for $item in $input
return (
if ($item instance of array(*))
then array:flatten(array:values($item))
then array:flatten(array:items($item))
else $item
)
};
Expand All @@ -29783,9 +29783,9 @@ declare function array:flatten(
</fos:example>
</fos:examples>
</fos:function>
<fos:function name="values" prefix="array">
<fos:function name="items" prefix="array">
<fos:signatures>
<fos:proto name="values" return-type="item()*">
<fos:proto name="items" return-type="item()*">
<fos:arg name="array" type="array(*)"/>
</fos:proto>
</fos:signatures>
Expand All @@ -29809,29 +29809,29 @@ declare function array:flatten(
<fos:notes>
<p>Unlike <function>array:flatten</function>, the function does not apply recursively
to nested arrays.</p>
<p>If <code>$A</code> is a single array item, then <code>array:values($A)</code>
<p>If <code>$A</code> is a single array item, then <code>array:items($A)</code>
returns the same result as <code>$A?*</code>.</p>
</fos:notes>
<fos:examples>
<fos:example>
<fos:test>
<fos:expression>array:values(["one", "two", "three"])</fos:expression>
<fos:expression>array:items(["one", "two", "three"])</fos:expression>
<fos:result>"one", "two", "three"</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:values(["one", ("two", "three")])</fos:expression>
<fos:expression>array:items(["one", ("two", "three")])</fos:expression>
<fos:result>"one", "two", "three"</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:values(["one", ("two", "three"), ()])</fos:expression>
<fos:expression>array:items(["one", ("two", "three"), ()])</fos:expression>
<fos:result>"one", "two", "three"</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:values(["one", ["two", "three"]])</fos:expression>
<fos:expression>array:items(["one", ["two", "three"]])</fos:expression>
<fos:result>"one", ["two", "three"]</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:values([ (), 1, (2 to 4), [ 5 ] ])</fos:expression>
<fos:expression>array:items([ (), 1, (2 to 4), [ 5 ] ])</fos:expression>
<fos:result>1, 2, 3, 4, [ 5 ]</fos:result>
</fos:test>
</fos:example>
Expand Down
16 changes: 8 additions & 8 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7713,7 +7713,7 @@ return <table>
</tr>
<tr>
<td><p>Extract the value part of a single entry</p></td>
<td><p><code>map:values($entry)</code></p></td>
<td><p><code>map:items($entry)</code></p></td>
<td><p><code>$key-value-pair?value</code></p></td>
</tr>
</tbody>
Expand Down Expand Up @@ -7799,6 +7799,9 @@ return <table>
<div3 id="func-map-get">
<head><?function map:get?></head>
</div3>
<div3 id="func-map-items" diff="add" at="2023-04-19">
<head><?function map:items?></head>
</div3>
<div3 id="func-map-keys">
<head><?function map:keys?></head>
</div3>
Expand Down Expand Up @@ -7832,9 +7835,6 @@ return <table>
<!--<div3 id="func-map-substitute" diff="add" at="A">
<head><?function map:substitute?></head>
</div3>-->
<div3 id="func-map-values" diff="add" at="2023-04-19">
<head><?function map:values?></head>
</div3>
</div2>

<div2 id="xml-to-json-mappings">
Expand Down Expand Up @@ -9332,7 +9332,7 @@ return <table>
... , <var>K/n</var> : <var>V/n</var> }</code> is equivalent to
<code>map:merge((map:entry(<var>K1</var>, <var>V1</var>), map:entry(<var>K1</var>, <var>V1</var>), ..., map:entry(<var>K/n</var>, <var>V/n</var>)), {"duplicates":"reject"})</code></p></item>
<item><p>The lookup expression <code>$map?*</code>
(see <xspecref spec="XP40" ref="id-lookup"/>) is equivalent to <code>map:values($map)</code>.</p></item>
(see <xspecref spec="XP40" ref="id-lookup"/>) is equivalent to <code>map:items($map)</code>.</p></item>
<item><p>The lookup expression <code>$map?K</code>, where <var>K</var> is a key value, is equivalent to
<code>map:get($map, <var>K</var>)</code></p></item>
<item><p>The expression <code>for key $k value $v in $map return <var>EXPR</var></code>
Expand Down Expand Up @@ -9469,6 +9469,9 @@ return <table>
<div3 id="func-array-insert-before">
<head><?function array:insert-before?></head>
</div3>
<div3 id="func-array-items" diff="add" at="2023-05-07">
<head><?function array:items?></head>
</div3>
<div3 id="func-array-join">
<head><?function array:join?></head>
</div3>
Expand Down Expand Up @@ -9511,9 +9514,6 @@ return <table>
<div3 id="func-array-trunk" diff="add" at="2022-11-16">
<head><?function array:trunk?></head>
</div3>
<div3 id="func-array-values" diff="add" at="2023-05-07">
<head><?function array:values?></head>
</div3>
</div2>
<div2 id="additional-array-operations" diff="add" at="2023-02-20">
<head>Other Operations on Arrays</head>
Expand Down
2 changes: 1 addition & 1 deletion specifications/xslt-40/src/xslt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14248,7 +14248,7 @@ and <code>version="1.0"</code> otherwise.</p>
the propagation of template parameters:</p>

<eg><![CDATA[<xsl:map-entry key="map:keys(.)">
<xsl:apply-templates select="map:values(.)" mode="#current"/>
<xsl:apply-templates select="map:items(.)" mode="#current"/>
</xsl:map-entry>]]></eg>

<p>The reason there is a special rule for maps with one entry is to ensure that the process
Expand Down
Loading