Changes

Jump to navigation Jump to search
2,453 bytes added ,  10:28, 18 January 2021
no edit summary
|}
 
=Array and Map Functions=
=Helper Functions=
 
==util:array-members==
 
{{Mark|Introduced with Version 9.5.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|util:array-members|$array as array(*)|array(*)*}}
|-
| '''Summary'''
|Returns each member of an {{Code|$array}} as a new array. Equivalent to: <code>for $a in 1 to array:size($array) return [ $array($a) ]</code>.
|-
| '''Examples'''
|
* Returns three elements with the member values as concatenated text node.
<syntaxhighlight lang="xquery">
let $array := [ (), 2, (3, 4) ]
for $member in array:members($array)
return element numbers { $member }
</syntaxhighlight>
|}
 
==util:array-values==
 
{{Mark|Introduced with Version 9.5.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|util:array-values|$array as array(*)|item()*}}
|-
| '''Summary'''
|Returns all members of an {{Code|$array}} as a sequence. Equivalent to {{Code|*?}}, but better composable and easier to read.
|-
| '''Examples'''
|
* Returns the array members as two items:
<syntaxhighlight lang="xquery">
let $array := [ (), 2, [ 3, 4 ] ]
return array:values($array)
</syntaxhighlight>
|}
 
==util:map-entries==
 
{{Mark|Introduced with Version 9.5.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|util:map-entries|$map as map(*)|map(xs:string, item()*)*}}
|-
| '''Summary'''
|Returns each entry (pair) of a {{Code|$map}} as a new map with, each with a {{Code|key}} and {{Code|value}} entry. Equivalent to: <code>map:for-each($map, function($key, $value) { map { "key": $key, "value": $value } })</code>.
|-
| '''Examples'''
|
* Returns three elements named by the key of the map, and with the entries as concatenated text node.
<syntaxhighlight lang="xquery">
let $map := map { 'a': (), 'b': 2, 'c': [ 3, 4 ] }
for $entry in map:entries($map)
return element { $entry?key } { string-join($entry?value) }
</syntaxhighlight>
|}
 
==util:map-values==
 
{{Mark|Introduced with Version 9.5.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|util:map-values|$map as map(*)|item()*}}
|-
| '''Summary'''
|Returns all values of a {{Code|$map}} as a sequence. Equivalent to {{Code|*?}}, but better composable and easier to read.
|-
| '''Examples'''
|
* Returns the map values as two items:
<syntaxhighlight lang="xquery">
let $map := map { 'a': (), 'b': 2, 'c': [ 3, 4 ] }
return map:values($map)
</syntaxhighlight>
|}
==util:replicate==
;Version 9.5
* Added: [[#util:intersperse|util:intersperse]], [[#util:within|util:within]], [[#util:duplicates|util:duplicates]], [[#util:array-members]], [[#util:array-values]], [[#util:map-entries]], [[#util:map-values]]
* Updated: [[#util:replicate|util:replicate]]: Third argument added.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu