The main difficulty is how to process an array that has sequences among its members, for example
[1 to 5, 6 to 10].
Then "for member $m in $A return sum($m)" returns (10, 40): it binds $m first to the sequence 1 to 5, then to the sequence 6 to 10.
You can tackle this with a higher-order function -- array:for-each($A, ->($m){sum($m)}) -- but it's hard to see how any kind of "flatten" function will deal with it.
Michael Kay
Saxonica
> On 18 Dec 2020, at 15:46, Christian Grün <cg@basex.org> wrote:
>
>> Then we need the array:flatten function to accept a "depth" parameter, and depth: 0 will be the default and cause the current behavior, that is unlimited depth, flatten all arrays until there are no more arrays.
>
> I thought about this option, too. But I believe that people who are
> used to Java and other languages don’t think about “flattening data”
> if all they want is accessing the contents of arrays. I believe the
> use case is common enough to provide an own function for that.
>