Changes

Jump to navigation Jump to search
|-
| '''Summary'''
|Applies the predicate function {{Code|$fpred}} to the initial value {{Code|$start}} until . If the predicate result is {{Code|false}}, {{Code|$predf}} applied to is invoked with the start value – or, subsequently, with the result of this function – until the predicate function returns {{Code|true()}}.
|-
| '''Examples'''
|
* {{Code|hof:Doubles a numeric value until(function($x) { $x ge 1000 }, function($y) { 2 * $y }, 1)}} returns {{Code|1024}}.* Calculating the square-root of a number by iteratively improving an initial guessmaximum is reached:
<pre class="brush:xquery">
hof:until( function($output) { $output ge 1000 }, function($input ) { 2 * $input }, 1)</pre>* Calculates the square-root of a number by iteratively improving an initial guess:<pre class="brush:xquery">let $sqrt := function($x input as xs:double) as xs:double {
hof:until(
function($resresult) { abs($res result * $res result - $xinput) < 0.00001 }, function($guess) { ($guess + $x input div $guess) div 2 }, $xinput
)
}
return $sqrt(25)
</pre>
returns * Returns {{Code|5.000000000053722OK}}. * The evaluation of , as the predicate is pre-fixed, thus every cycle starts with the evaluation of the predicate evaluated first.:
<pre class="brush:xquery">
declare hof:until( function local:pred($res_) { true() };,declare function local:loop($val_) { $val + 1 error() };, 'OK'hof:until(local:pred#1, local:loop#1, 0)
</pre>
returns {{Code|0}}.
 
|}
* With higher-order functions:
<pre class="brush:xquery">
let $sort := sort(?, (), hof:id#1)let $reverse-sort := sort(?, (), function($x) { -$x })
return (
$sort((1, 5, 3, 2, 4)),
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu