Changes

Jump to navigation Jump to search
m
Text replace - "| valign='top' | " to "| "
|<code><b>hof:id</b>($expr as item()*) as item()*</code>
|-
| valign='top' | '''Summary'''
|Returns its argument unchanged. This function isn't useful on its own, but can be used as argument to other higher-order functions.
|-
| valign='top' | '''Examples'''
|
* <code>hof:id(1 to 5)</code> returns <code>1 2 3 4 5</code>
|<code><b>hof:const</b>($expr as item()*, $ignored as item()*) as item()*</code>
|-
| valign='top' | '''Summary'''
|Returns its first argument unchanged and irgores the second. This function isn't useful on its own, but can be used as argument to other higher-order functions, e.g. when a function combining two values is expected and one only wants to retain the left one.
|-
| valign='top' | '''Examples'''
|
* <code>hof:const(42, 1337)</code> returns <code>42</code>.
|<code><b>hof:fold-left1</b>($f as function(item()*, item()) as item()*, $seq as item()+) as item()*</code>
|-
| valign='top' | '''Summary'''
|Works the same as [[Higher-Order_Functions#fn:fold-left($f, $seed, $seq)|fn:fold-left($f, $seed, $seq)]], but doesn't need a seed, because the sequence must be non-empty.
|-
| valign='top' | '''Errors'''
|''XPTY0004'' if <code>$seq</code> is empty
|-
| valign='top' | '''Examples'''
|
* <code>hof:fold-left1(function($a, $b) { $a + $b }, 1 to 10)</code> returns <code>55</code>.
|<code><b>hof:until</b>($pred as function(item()*) as xs:boolean, $f as function(item()*) as item()*, $start as item()*) as item()*</code>
|-
| valign='top' | '''Summary'''
|Applies the function <code>$f</code> to the initial value <code>$start</code> until the predicate <code>$pred</code> applied to the result returns <code>true()</code>.
|-
| valign='top' | '''Examples'''
|
* <code>hof:until(function($x) { $x ge 1000 }, function($y) { 2 * $y }, 1)</code> returns <code>1024</code>.
|<code><b>hof:top-k-by</b>($seq as item()*, $sort-key as function(item()) as item(), $k as xs:integer) as item()*</code>
|-
| valign='top' | '''Summary'''
|Returns the <code>$k</code> items in <code>$seq</code> that are greatest when sorted by the result of <code>$f</code> applied to the item. The function is a much more efficient implementation of the following scheme:
<pre class="brush:xquery">
</pre>
|-
| valign='top' | '''Errors'''
|''XPTY0004'' if <code>$sort-key</code> doesn't return exactly one item
|-
| valign='top' | '''Examples'''
|
* <code>hof:top-k-by(1 to 1000, hof:id#1, 5)</code> returns <code>1000 999 998 997 996</code>
|<code><b>hof:top-k-with</b>($seq as item()*, $lt as function(item(), item()) as xs:boolean, $k as xs:integer) as item()*</code>
|-
| valign='top' | '''Summary'''
|Returns the <code>$k</code> items in <code>$seq</code> that are greatest when sorted in the order of the ''less-than'' predicate <code>$lt</code>. The function is a general version of <code>hof:top-k-by($seq, $sort-key, $k)</code>.
|-
| valign='top' | '''Examples'''
|
* <code>hof:top-k-with(1 to 1000, function($a, $b) { $a lt $b }, 5)</code> returns <code>1000 999 998 997 996</code>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu