Changes

Jump to navigation Jump to search
39 bytes added ,  22:56, 19 May 2013
no edit summary
$f as function(item()) as item()*
) as function(item()*) as item()* {
fn:mapfor-each($f, ?)
};
</pre>
We'll see later how <code>fn:mapfor-each(...)</code> works. The type of <code>local:on-sequences(...)</code> on the other hand is easily constructed, if a bit long:
<code>function(function(item()) as item()*) as function(item()*) as item()*</code>.
<ul><li>Squaring all numbers from 1 to 10:
<pre class="brush:xquery">
fn:mapfor-each(1 to 10, math:pow(?, 2))
</pre>
''Result:'' <code>1 4 9 16 25 36 49 64 81 100</code>
fn:string-length#1
)
return fn:mapfor-each($fs, function($f) { $f('foobar') })
</pre>
''Result:'' <code>FOOBAR bar 6</code>
|-
| '''Note'''
|<code>fn:filter</code> can be easily implemented with <code>fn:mapfor-each</code>:
<pre class="brush:xquery">
declare function local:filter($pred, $seq) {
mapfor-each(
$seq,
function($x) {
|<ul><li>Adding one to the numbers at odd positions:
<pre class="brush:xquery">
fn:mapfor-pairseach-pair( fn:mapfor-each(1 to 10, function($x) { $x mod 2 }),
(1, 1, 1, 1, 1),
function($a, $b) { $a + $b },
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu