I am new to the functional programming paradigm and Xquery. As part of a larger exercise, I wanted to sum the digits of an integer. The first part of that problem is to solve the smaller problem: convert an integer to a sequence of integers that I can then pass to fn:sum as a parameter.
(: I've declared the function in the nwnu namespace for testing purposes :)
declare function nwnu:number-to-seq($num as xs:integer)
as xs:integer* {
if($num gt 9) then
(
nwnu:number-to-seq(xs:integer(math:floor($num div 10))),
xs:integer(math:floor($num mod 10))
)
else
$num
};
[Read More]