This module provides a compose function.
The module and default function namespaces are https://tinyurl.com/9apf36he
.
This function applies each function in the $functions
sequence to the $items
sequence. If $functions
is empty, it returns $items
. Otherwise, it recursively applies the first function in $functions
to each item in $items
, and then calls itself with the result and the remaining functions.
$items
: The items to be processed. It is of typeitem()*
.$functions
: The functions to be applied to the items. It is of typefunction(item()*)*
.
The result of applying each function to the items. The return type is item()*
.
declare function compose(
$items as item()*,
$functions as function(item()*) as item()**
) as item()* {
if (fn:empty($functions)) then $items
else compose(fn:for-each($items, fn:head($functions)), fn:tail($functions))
};
: https://en.wikipedia.org/wiki/Function_composition_(computer_science)