Changes

Jump to navigation Jump to search
240 bytes removed ,  00:42, 26 May 2012
m
Text replace - "| valign='top' | " to "| "
|<code><b>fn:map</b>($f as function(item()) as item()*, $seq as item()*) as item()*</code><br />
|-
| valign='top' | '''Summary'''
|Applies the function item <code>$f</code> to every element of the sequence <code>$seq</code> and returns all of the results as a sequence.
|-
| valign='top' | '''Examples'''
|
<ul><li>Squaring all numbers from 1 to 10:
</li></ul>
|-
| valign='top' | '''XQuery 1.0'''
|<pre class="brush:xquery">
declare function local:map(
|<code><b>fn:filter</b>($pred as function(item()) as xs:boolean, $seq as item()*) as item()*</code><br />
|-
| valign='top' | '''Summary'''
|Applies the boolean predicate <code>$pred</code> to all elements of the sequence <code>$seq</code>, returning those for which it returns <code>true()</code>.
|-
| valign='top' | '''Examples'''
|<ul><li>All even integers until 10:
<pre class="brush:xquery">
</li></ul>
|-
| valign='top' | '''Note'''
|<code>fn:filter</code> can be easily implemented with <code>fn:map</code>:
<pre class="brush:xquery">
</pre>
|-
| valign='top' | '''XQuery 1.0'''
|<pre class="brush:xquery">
declare function local:filter(
|<code><b>fn:map-pairs</b>($f as function(item(), item()) as item()*, $seq1 as item()*, $seq2 as item()*) as item()*</code><br />
|-
| valign='top' | '''Summary'''
|''zips'' the elements from the two sequences <code>$seq1</code> and <code>$seq2</code> together with the function <code>$f</code>. It stops after the shorter sequence ends.
|-
| valign='top' | '''Examples'''
|<ul><li>Adding one to the numbers at odd positions:
<pre class="brush:xquery">
''Result:'' <code>true false</code>
|-
| valign='top' | '''XQuery 1.0'''
|<pre class="brush:xquery">
declare function local:map-pairs(
|<code><b>fn:fold-left</b>($f as function(item()*, item()) as item()*, $seed as item()*, $seq as item()*) as item()*</code><br />
|-
| valign='top' | '''Summary'''
|The ''left fold'' traverses the sequence from the left.
The query <code>fn:fold-left($f, 0, 1 to 5)</code> for example would be evaluated as:
</pre>
|-
| valign='top' | '''Examples'''
|<ul><li>Product of a sequence of integers:
<pre class="brush:xquery">
</li></ul>
|-
| valign='top' | '''XQuery 1.0'''
|As folds are more general than ''FLWOR'' expressions, the implementation isn't as concise as the former ones:
<pre class="brush:xquery">
|<code><b>fn:fold-right</b>($f as function(item(), item()*) as item()*, $seed as item()*, $seq as item()*) as item()*</code><br />
|-
| valign='top' | '''Summary'''
|The ''right fold'' <code>fn:fold-right($f, $seed, $seq)</code> traverses the from the right.
The query <code>fn:fold-right($f, 0, 1 to 5)</code> for example would be evaluated as:
</pre>
|-
| valign='top' | '''Examples'''
|<ul><li>Product of a sequence of integers:
<pre class="brush:xquery">
</li></ul>
|-
| valign='top' | '''XQuery 1.0'''
|<pre class="brush:xquery">
declare function local:fold-right(
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu