BaseX 11 · This is the documentation of an older version. Current version →
Higher-Order Functions
This module adds some useful higher-order functions, additional to the standard Higher-Order Functions provided by the official specification.
Removed: Some functions have been removed in favor of new XQuery 4 standard functions:
| BaseX 10 | XQuery 4 |
hof:drop-while |
fn:subsequence-where |
hof:id, hof:const |
fn:identity |
hof:until |
fn:while-do, fn:do-until |
hof:take-while |
fn:take-while |
Conventions
All functions in this module are assigned to the http://basex.org/modules/hof namespace, which is statically bound to the hof prefix.
Loops
hof:fold-left1
| Signature | hof:fold-left1( $input as item()+, $action as fn(item()*, item()) as item()*) as item()* |
|---|---|
| Summary | Works the same as fn:fold-left, but does not need a seed, because the sequence must be non-empty. |
| Examples | Result: 55Raises XPTY0004, because $seq has to be non-empty. |
hof:scan-left
| Signature | hof:scan-left( $input as item()*, $zero as item()*, $action as fn(item()*, item()) as item()*) as item()* |
|---|---|
| Summary | This function is similar to fn:fold-left, but it returns a list of successive reduced values from the left. It is equivalent to:
|
| Examples | Result: 0, 1, 3, 6, 10, 15. Computes triangular numbers. |
Sorting
hof:top-k-by
| Signature | hof:top-k-by( $input as item()*, $key as fn(item()) as item(), $k as xs:integer) as item()* |
|---|---|
| Summary | Returns the $k items in $input that are greatest when sorted by the result of $key applied to the item. The function is a much more efficient implementation of the following scheme:
|
| Examples | Result: 1000, 999, 998, 997, 996 Result: 1, 2, 3 Result: 'c', 'b' |
hof:top-k-with
| Signature | hof:top-k-with( $input as item()*, $comparator as fn(item(), item()) as xs:boolean, $k as xs:integer) as item()* |
|---|---|
| Summary | Returns the $k items in $input that are greatest when sorted in the order of the less-than predicate $comparator. The function is a general version of hof:top-k-by. |
| Examples | Result: 1000, 999, 998, 997, 996 Result: 0, 1, -1, 2, -2 |
Changelog
Version 11.0- Removed:
hof:until(replaced withfn:while-do/fn:do-until,hof:id/hof:const(replaced withfn:identity,hof:drop-while(replaced withfn:subsequence-where),hof:take-while(replaced withfn:take-while)
- Added:
hof:drop-while
- Added:
hof:scan-left,hof:take-while
- Added:
hof:top-k-by,hof:top-k-with - Removed: hof:iterate
- Added: The module was added with Version 7.0.
⚡Generated with XQuery