Changes

Jump to navigation Jump to search
1,632 bytes added ,  11:56, 6 March 2015
no edit summary
==hof:id==
 
{| width='100%'
|-
==hof:const==
 
{| width='100%'
|-
==hof:until==
 
{| width='100%'
|-
</pre>
returns {{Code|5.000000000053722}}.
|}
 
==hof:scan-left==
 
{{Mark|Introduced with Version 8.1}}:
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|hof:scan-left|$seq as item()*, $start as item()*, $f as function(item()*, item()) as item()*|item()*}}
|-
| '''Summary'''
|This function is similar to [[Higher-Order Functions#fn:fold-left|fn:fold-left]], but it returns a list of successive reduced values from the left. It is equivalent to:
<pre class="brush:xquery">
declare function hof:scan-left($seq, $acc, $f) {
if(empty($seq)) then $acc else (
$acc,
hof:scan-left(tail($seq), $f($acc, head($seq)), $f)
)
};
</pre>
|-
| '''Examples'''
|
* Returns triangular numbers:
<pre class="brush:xquery">
hof:scan-left(1 to 10, 0, function($a, $b) { $a + $b })
</pre>
|}
 
==hof:take-while==
 
{{Mark|Introduced with Version 8.1}}:
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|hof:take-while|$seq as item()*, $pred as function(item()) as xs:boolean|item()*}}
|-
| '''Summary'''
|The function returns items of <code>$seq</code> as long as the predicate <code>$pred</code> is satisfied. It is equivalent to:
<pre class="brush:xquery">
declare function hof:take-while($seq, $pred) {
if(empty($seq) or not($pred(head($seq)))) then () else (
head($seq),
hof:take-while(tail($seq), $pred)
)
};
</pre>
|-
| '''Examples'''
|
* Computes at most 100 random integers, but stops if an integer is smaller than 10:
<pre class="brush:xquery">
hof:take-while(
for $i in 1 to 100
return random:integer(50),
function($x) { $x >= 10 }
)
</pre>
|}
=Changelog=
 
;Version 8.1
 
* Added: [[#hof:scan-left|hof:scan-left]], [[#hof:take-while|hof:take-while]]
;Version 7.2
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu