Arrow expressions apply a function to a value, using the value of the left-hand expression as the first argument to the function.
@@ -22162,30 +22168,35 @@ return string-join($chopped, '; ') =!> upper-case() => string-join(" ")]]> -returns "THE. CAT. SAT. ON. THE. MAT."
. The first arrow
+
returns "THE. CAT. SAT. ON. THE. MAT."
. The first arrow
could be written either as =>
or =!>
because the operand is a singleton; the next two
arrows have to be =!>
because the function is applied to each item in the tokenized
sequence individually; the final arrow must be =>
because the string-join
function applies to the sequence as a whole.
It may be useful to think of this as a map/reduce pipeline. The functions
+ It may be useful to think of this as a map/reduce pipeline. The functions
introduced by =!>
are mapping operations; the function introduced by =>
is a reduce operation.
The following example introduces an inline function to the pipeline:
+The following example introduces an inline function to the pipeline:
This is equivalent to sum((1 to 5) ! (math:sqrt(xs:double(.)) + 1))
.
This is equivalent to sum((1 to 5) ! (math:sqrt(xs:double(.)) + 1))
.
The same effect can be achieved using a
The same effect can be achieved using a
It could also be expressed using the mapping operator !
:
Where the value of an expression is a map containing functions, simulating the behavior
of objects in object-oriented languages, then the =?>
- can be used to retrive a function from the map and to invoke the function with the map as its
+ can be used to retrieve a function from the map and to invoke the function with the map as its
first argument. For example, if my:rectangle
returns a map with entries width
,
height
, expand
, and area
, then it becomes possible to
write:
The The ArgumentList
may include PlaceHolders
,
+ ArgumentList
of the function call
+ may include PlaceHolders
,
though this is not especially useful. For example, the expression "$" => concat(?)
is equivalent
to concat("$", ?)
: its value is a function that prepends a supplied string with
a $
symbol.
The expression U => $V(X)(Y)
satisfies the grammar, but its meaning
+ might not be obvious. It is interpreted as being equivalent to $V(X)(U, Y)
.
+ The same applies to the mapping arrow operator: U =!> $V(X)(Y)
is
+ interpreted as for $u in $V return $V(X)($u, Y)
. This follows from
+ the way that the syntax of a
Given a U
, an F
, and an (A, B, C...)
, the expression U => F(A, B, C...)
is equivalent to the
- expression F(U, A, B, C...)
.
Given a U
, an F
, and an (A, B, C...)
, the expression U => F(A, B, C...)
is equivalent to the
- expression F(U, A, B, C...)
.
If the arrow is followed by a static
Given a F(A, B, C...)
,
+ the expression U => F(A, B, C...)
+ is equivalent to the expression
+ F(U, A, B, C...)
.
If the arrow is followed by a
Given a E(A, B, C...)
, the expression
+ U => E(A, B, C...)
is equivalent to the
+ expression E(U, A, B, C...)
.
Although the syntax of an arrow expression makes use of the grammatical productions
+
If the arrow is followed by an Given a If the arrow is followed by a static Given a If the arrow is followed by an Given a If the arrow is followed by a Given a =!>
applies a function to each
item in a sequence.U
, an F
, and an (A, B, C...)
, the expression U =!> F(A, B, C...)
is equivalent to the
- expression (for $u in U return F($u, A, B, C...))
.F(A, B, C...)
,
+ the expression U =!> F(A, B, C...)
+ is equivalent to the expression
+ for $u in U return
+ F($u, A, B, C...)
.U
, an F
, and an (A, B, C...)
, the expression U =!> F(A, B, C...)
is equivalent to the
- expression (for $u in U return F($u, A, B, C...))
.E(A, B, C...)
, the expression
+ U => E(A, B, C...)
is equivalent to the
+ expression for $u in U return E($u, A, B, C...)
.