Changes

Jump to navigation Jump to search
no edit summary
| width='120' | '''Signature'''
|<pre>hof:fold-left1(
$seq input as item()+, $f action as function(item()* , item()) as item()*
) as item()*</pre>
|- valign="top"
| width='120' | '''Signature'''
|<pre>hof:until(
$pred predicate as function(item()*)as xs:boolean, $f action as function(item()*)as item()*, $start zero as item()*
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Applies the predicate function {{Code|$predpredicate}} to {{Code|$startzero}}. If the result is {{Code|false}}, {{Code|$faction}} is invoked with the start value – or, subsequently, with the result of this function – until the predicate function returns {{Code|true()}}.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>hof:scan-left(
$seq input as item()*, $start zero as item()*, $f action as function(item()* , item()) as item()*
) as item()*</pre>
|- valign="top"
|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:
<syntaxhighlight lang="xquery">
declare function hof:scan-left($seqinput, $acc, $faction) { if(empty($seqinput)) then $acc else (
$acc,
hof:scan-left(tail($seqinput), $faction($acc, head($seqinput)), $faction)
)
};
| width='120' | '''Signature'''
|<pre>hof:take-while(
$seq input as item()*, $pred predicate as function(item())
) as item()*</pre>
|- valign="top"
| '''Summary'''
|The function returns items of <code>$seqinput</code> as long as the predicate <code>$predpredicate</code> is satisfied. It is equivalent to:
<syntaxhighlight lang="xquery">
declare function hof:take-while($seqinput, $predpredicate) { if(empty($seqinput) or not($predpredicate(head($seqinput)))) then () else ( head($seqinput), hof:take-while(tail($seqinput), $predpredicate)
)
};
| width='120' | '''Signature'''
|<pre>hof:drop-while(
$seq input as item()* $pred predicate as function(item()*)as xs:boolean
) as item()*</pre>
|- valign="top"
| '''Summary'''
|The function skips all items of <code>$seqinput</code> until the predicate <code>$predpredicate</code> is not satisfied anymore. It is equivalent to:
<syntaxhighlight lang="xquery">
declare function hof:drop-while($seqinput, $predpredicate) { if($predpredicate(head($seqinput))) then ( hof:drop-while(tail($seqinput), $predpredicate)
) else (
$seqinput
)
};
| width='120' | '''Signature'''
|<pre>hof:top-k-by(
$seq input as item()* $sort-key as function(item()) as item() $k as xs:integer
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Returns the {{Code|$k}} items in {{Code|$seqinput}} that are greatest when sorted by the result of {{Code|$fkey}} applied to the item. The function is a much more efficient implementation of the following scheme:
<syntaxhighlight lang="xquery">
(for $x item in $seqinput order by $sort-key($xitem) descending return $xitem
)[position() <= $k]
</syntaxhighlight>
| width='120' | '''Signature'''
|<pre>hof:top-k-with(
$seq input as item()* $lt comparator as function(item() , item()) as xs:boolean $k as xs:integer
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Returns the {{Code|$k}} items in {{Code|$seqinput}} that are greatest when sorted in the order of the ''less-than'' predicate {{Code|$ltcomparator}}. The function is a general version of {{CodeFunction||hof:top-k-by($seq, $sort-key, $k)}}.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>hof:id(
$expr input as item()*
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Returns its argument unchanged. This function isn’t useful on its own, but can be used as an argument to other higher-order functions.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>hof:const(
$expr input as item()*, $ignored ignore as item()*
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Returns its first argument unchanged and ignores 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'''
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu