Yes !
fold-* functions are not intuitive, and tutorials will be welcome !
Christophe
Le 12 mars 2025 à 11:36, "Christian Grün" <cg@basex.org> a écrit :
> In most case it's easy enough, for example fn:filter becomes
>
> fold-left($input ! {'item': ., 'pos': position()},
> (),
> fn($result, $pair) {
> if ($predicate($pair?item, $pair?pos))
> then ($result, $pair?item)
> else $result
> })
…and the function call would need to be followed by an ?item lookup.
One question may be who is supposed to be the recipient of the equivalent code. If we want to address users, I think that we should focus on simplicity. For fn:filter, a FLWOR expression may be much easier to digest:
for $item at $pos in $input
where $predicate($item, $pos)
return $item
Next, many functions (including fn:index-of or fn:avg) don’t seem to have a formal counterpart. Maybe it’s not required in all cases? Folds are a good example: For advanced users, it is obvious what it does, and there will be no need to digest the equivalent code. For others, the main challenge is to understand the very principle, and tutorials will probably be more helpful than a concise recursive function.