Re: Allowing the for member syntax to enumerate key/value pairs in a map.

> 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.

Absolutely true. For this purpose, array:members() would do the job:

  array:members($A) ! sum(.)

The functions array:values() and map:values() can be seen as aliases
for the *? shortcut (I’ve added some more details in a new GitHub
issue, https://github.com/qt4cg/qtspecs/issues/29).
____________________________________

On Fri, Dec 18, 2020 at 5:32 PM Michael Kay <mike@saxonica.com> wrote:
>
> 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.
>
>

Received on Friday, 18 December 2020 16:39:39 UTC