Database Reference
In-Depth Information
let
$
f
:=
upper-case
#
1
return
local:map-example
(
$
f
,
(
"Hello"
,
"world!"
))
We first define a function,
local:map
, that runs the function passed in its first
parameter,
$func
, over all members of its second operand,
$list
.
We then assign the
upper-case
function to
$f
. The
#1
after the function name
means that we want the
upper-case
function with only one parameter (in case
there are more).
Finally, we call
local:map
with our function and some input strings. It returns
the expected
HELLO WORLD!
.
Higher-order functions is a serious subject in its own right and includes topics such
as: inline and partial functions, closures, currying, and more. For further informa‐
tion, you can refer to the XQuery 3.0 specification and to this excellent
eXist wiki
article
.
The simple map operator
The XQuery 3.0 bang operator
!
(or simple map operator, as it is officially called) can
be seen as a shorthand for simple FLWOR expressions. It applies the right-hand
expression to each item in the sequence gained from evaluating the left-hand expres‐
sion. For instance:
(
1
to
10
)
!
.
+
1
is the same as:
for
$
i
in
(
1
to
10
)
return
$
i
+
1
The string concatenation operator
The string concatenation operator
||
is a shorthand replacement for the
concat
function: it concatenates strings. For example, the following expression will be true:
'Hello '
||
'world'
eq
concat
(
'Hello '
,
'world'
)
Annotations
XQuery 3.0 allows annotations for functions and variables. This is used, for instance,
to make them private (visible only in the enclosing module) or public:
declare
%private
variable
$
myns:only-i-can-see-this
:=
'secret'
;
declare
%public
function
myns:do-something-public
()
{
Search WWH ::
Custom Search