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

I'm reluctant. I don't think this requirement is frequent enough to justify custom syntax. What's wrong with

map:for-each($map, ->($key, $value){``[`{$key}`=`{$value}`]``}

Higher-order functions mean we can do an awful lot more without ad-hoc syntax.

Michael Kay
Saxonica

> On 17 Dec 2020, at 20:24, Reece Dunn <msclrhd@googlemail.com> wrote:
> 
> Given the new `for member` syntax support for enumerating over the items in an array, it would be useful to have an easy way of enumerating over the key/value pairs in a map. This could be done through the same `for member` syntax, but the members for a map would be a 2-item sequence or a map of the key/value pairs in the map in an implementation-defined stable order.
> 
> If the variant of this proposal to use a map for the key/value pairs is used, then given a map of type `map(K, V)` the member RecordTest would be `record(key as K, value as V)`. For a `map(*)` type, the member RecordTest would be `record(key, value)`.
> 
> Combined with sequence/map/array decomposition, this would allow a user to write expressions like:
> 
>     for member ${key, value} in $map
>     return ``[`{$key}`=`{value}`]``
> 
> It may be useful to have a different keyword to denote maps, such as `entry` like JavaScript and Java, or `item` like Python, but using `member` for both arrays and maps would be more consistent with the user wanting to enumerate over the content of those data structures.
> 
> Kind regards,
> Reece

Received on Thursday, 17 December 2020 20:34:29 UTC