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

868 fn:intersperse → fn:join, array:join($arrays, $separator) #1504

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
94 changes: 56 additions & 38 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4923,11 +4923,7 @@ return normalize-unicode(concat($v1, $v2))</eg>
</fos:example>

<fos:variable name="doc" id="v-string-join-doc"
>&lt;doc&gt;
&lt;chap&gt;
&lt;section xml:id="xyz"/&gt;
&lt;/chap&gt;
&lt;/doc&gt;</fos:variable>
>&lt;doc&gt;&lt;chap&gt;&lt;section xml:id="xyz"/&gt;&lt;/chap&gt;&lt;/doc&gt;</fos:variable>
<fos:example>
<fos:test use="v-string-join-doc" spec="XQuery">
<fos:expression><eg>$doc//@xml:id
Expand Down Expand Up @@ -14442,9 +14438,9 @@ filter($input, fn($item, $pos) { $pos gt 1 })
</fos:changes>
</fos:function>

<fos:function name="intersperse" prefix="fn">
<fos:function name="sequence-join" prefix="fn">
<fos:signatures>
<fos:proto name="intersperse" return-type="item()*">
<fos:proto name="sequence-join" return-type="item()*">
<fos:arg name="input" type="item()*" usage="navigation"/>
<fos:arg name="separator" type="item()*" usage="navigation"/>
</fos:proto>
Expand All @@ -14458,47 +14454,42 @@ filter($input, fn($item, $pos) { $pos gt 1 })
<p>Inserts a separator between adjacent items in a sequence.</p>
</fos:summary>
<fos:rules>
<p>The function returns the value of <code>head($input), tail($input) ! ($separator, .)</code>.</p>
<p>The function inserts a separator between adjacent items in a sequence.
The input is returned unchanged if <code>$separator</code> is the empty sequence
or if <code>$input</code> contains less than two items.</p>
</fos:rules>
<fos:equivalent style="xpath-expression">
for-each($input, fn($item, $pos) {
if ($pos eq 1)
then $item
else ($separator, $item)
if ($pos gt 1) { $separator },
$item
})
</fos:equivalent>
<fos:notes>
<p>If <code>$input</code> contains less than two items then it is returned unchanged.</p>
<p>If <code>$separator</code> is the empty sequence then <code>$input</code> is returned unchanged.</p>
<p>For example, in XQuery, <code>fn:intersperse(para, &lt;hr/>)</code> would insert
an empty <code>hr</code> element between adjacent paragraphs.</p>
</fos:notes>
<fos:examples>
<fos:example>
<fos:test>
<fos:expression>intersperse(1 to 5, "|")</fos:expression>
<fos:expression>sequence-join(1 to 5, "|")</fos:expression>
<fos:result>(1, "|", 2, "|" , 3, "|", 4, "|", 5)</fos:result>
</fos:test>
<fos:test>
<fos:expression>intersperse((), "|")</fos:expression>
<fos:expression>sequence-join((), "|")</fos:expression>
<fos:result>()</fos:result>
</fos:test>
<fos:test>
<fos:expression>intersperse("A", "|")</fos:expression>
<fos:expression>sequence-join("A", "|")</fos:expression>
<fos:result>"A"</fos:result>
</fos:test>
<fos:test>
<fos:expression>intersperse(1 to 5, ())</fos:expression>
<fos:result>(1, 2, 3, 4, 5)</fos:result>
</fos:test>
<fos:test>
<fos:expression>intersperse(1 to 3, ("⅓", "⅔"))</fos:expression>
<fos:expression>sequence-join(1 to 3, ("⅓", "⅔"))</fos:expression>
<fos:result>(1, "⅓", "⅔", 2, "⅓", "⅔", 3)</fos:result>
</fos:test>
</fos:example>
<fos:example>
<p>Insert an empty <code>hr</code> element between adjacent paragraphs:</p>
<eg><![CDATA[sequence-join(./para, <hr/>)]]></eg>
</fos:example>
</fos:examples>
<fos:changes>
<fos:change issue="2" date="2022-09-27"><p>New in 4.0</p></fos:change>
<fos:change issue="2 868" date="2022-09-27"><p>New in 4.0</p></fos:change>
</fos:changes>
</fos:function>

Expand Down Expand Up @@ -27080,6 +27071,7 @@ $array
<fos:signatures>
<fos:proto name="join" return-type="array(*)">
<fos:arg name="arrays" type="array(*)*" usage="inspection"/>
<fos:arg name="separator" type="array(*)?" default="()" usage="navigation"/>
</fos:proto>
</fos:signatures>
<fos:properties>
Expand All @@ -27088,16 +27080,22 @@ $array
<fos:property>focus-independent</fos:property>
</fos:properties>
<fos:summary>
<p>Concatenates the contents of several arrays into a single array.</p>
<p>Concatenates the contents of several arrays into a single array, with an optional
separator between adjacent members.</p>
</fos:summary>
<fos:rules>
<p>Informally, the function concatenates the members of several arrays into a single array.</p>
<!--<p diff="chg" at="A">More formally, the function returns the result of
<code>array:of-members($arrays ! array:members(.))</code>.</p>-->
<p>Informally, the function concatenates the members of several arrays into a single array.
If a separator is supplied, its members are inserted before the members of the second
and the following arrays.</p>
</fos:rules>
<fos:equivalent style="xpath-expression"><![CDATA[
array:of-members($arrays ! array:members(.))
]]></fos:equivalent>
array:of-members(
for-each($arrays, fn($array, $pos) {
if ($pos gt 1 and exists($separator)) { array:members($separator) },
array:members($array)
})
)
]]></fos:equivalent>
<fos:examples>
<fos:example>
<fos:test>
Expand All @@ -27109,16 +27107,36 @@ $array
<fos:result>[ 1, 2, 3 ]</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:join(([ "a", "b" ], [ "c", "d" ]))</fos:expression>
<fos:result>[ "a", "b", "c", "d" ]</fos:result>
<fos:expression>array:join(([ "a", "b" ], [ "c" ]))</fos:expression>
<fos:result>[ "a", "b", "c" ]</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:join(([ "a", "b" ], [ "c", "d" ], []))</fos:expression>
<fos:result>[ "a", "b", "c", "d" ]</fos:result>
<fos:expression>array:join(([ "a", "b" ], [ "c" ], []))</fos:expression>
<fos:result>[ "a", "b", "c" ]</fos:result>
</fos:test>
<fos:test>
<fos:expression>array:join(([ "a", "b" ], [ [ "c", "d" ] ]))</fos:expression>
<fos:result>[ "a", "b", [ "c", "d" ] ]</fos:result>
<fos:expression>array:join(([ "a", "b" ], [ [ "c" ] ]))</fos:expression>
<fos:result>[ "a", "b", [ "c" ] ]</fos:result>
</fos:test>
<fos:test>
<fos:expression><eg>array:join(
characters('abc') ! array { . },
[ "/" ]
)</eg></fos:expression>
<fos:result>[ "a", "/", "b", "/", "c" ]</fos:result>
</fos:test>
<fos:test>
<fos:expression><eg>array { 1 to 3 }
=> array:split()
=> array:join([ () ])</eg></fos:expression>
<fos:result>[ 1, (), 2, (), 3 ]</fos:result>
</fos:test>
<fos:test>
<fos:expression><eg>array:join(
([ () ], [ 1, (2, 3) ]),
[ "a", ("b", "c") ]
)</eg></fos:expression>
<fos:result>[(), "a", ("b", "c"), 1, (2, 3)]</fos:result>
</fos:test>
</fos:example>
</fos:examples>
Expand Down
6 changes: 3 additions & 3 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5514,9 +5514,6 @@ correctly in all browsers, depending on the system configuration.</emph></p>-->
<div3 id="func-insert-before">
<head><?function fn:insert-before?></head>
</div3>
<div3 id="func-intersperse" diff="add" at="A">
<head><?function fn:intersperse?></head>
</div3>
<div3 id="func-items-at" diff="add" at="2022-11-16">
<head><?function fn:items-at?></head>
</div3>
Expand All @@ -5529,6 +5526,9 @@ correctly in all browsers, depending on the system configuration.</emph></p>-->
<div3 id="func-reverse">
<head><?function fn:reverse?></head>
</div3>
<div3 id="func-sequence-join" diff="add" at="A">
<head><?function fn:sequence-join?></head>
</div3>
<div3 id="func-slice" diff="add" at="A">
<head><?function fn:slice?></head>
</div3>
Expand Down