Changes

Jump to navigation Jump to search
1,518 bytes removed ,  17:20, 11 November 2023
no edit summary
<syntaxhighlight lang="xquery">
hof:scan-left(1 to 10, 0, function($a, $b) { $a + $b })
</syntaxhighlight>
|}
 
==hof:take-while==
 
{| width='100%'
|- valign="top"
| width='120' | '''Signature'''
|<pre>hof:take-while(
$input as item()*,
$predicate as function(item()) as xs:boolean
) as item()*</pre>
|- valign="top"
| '''Summary'''
|The function returns items of <code>$input</code> as long as the <code>$predicate</code> is satisfied. It is equivalent to:
<syntaxhighlight lang="xquery">
declare function hof:take-while($input, $predicate) {
if(empty($input) or not($predicate(head($input)))) then () else (
head($input),
hof:take-while(tail($input), $predicate)
)
};
</syntaxhighlight>
|- valign="top"
| '''Examples'''
|
* Computes at most 100 random integers, but stops if an integer is smaller than 10:
<syntaxhighlight lang="xquery">
hof:take-while(
(1 to 100) ! random:integer(50),
function($x) { $x >= 10 }
)
</syntaxhighlight>
|}
 
==hof:drop-while==
 
{| width='100%'
|- valign="top"
| width='120' | '''Signature'''
|<pre>hof:drop-while(
$input as item()*,
$predicate as function(item()*) as xs:boolean
) as item()*</pre>
|- valign="top"
| '''Summary'''
|The function skips all items of <code>$input</code> until the <code>$predicate</code> is not satisfied anymore. It is equivalent to:
<syntaxhighlight lang="xquery">
declare function hof:drop-while($input, $predicate) {
if($predicate(head($input))) then (
hof:drop-while(tail($input), $predicate)
) else (
$input
)
};
</syntaxhighlight>
|- valign="top"
| '''Examples'''
|Returns the name of the first file that does not exist on disk:
<syntaxhighlight lang="xquery">
hof:drop-while(
(1 to 1000) ! (. || '.log'),
file:exists#1
)[1]
</syntaxhighlight>
|}
;Version 11.0
* Removed: {{Code|hof:until}} (replaced with {{Code|fn:iterate-while}}, {{Code|hof:if}} (replaced with {{Code|fn:identity}}, {{Code|hof:drop-while}} (replaced with {{Code|fn:items-starting-where}}), {{Code|hof:take-while}} (replaced with {{Code|fn:items-before}})
;Version 9.5
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu