Hi all -
I would appreciate some help understanding how I might go about having a multi-valued array as the value of a map key, or if this is even possible; e.g.
map{ "key": [1,2,3,4,5] }
I've tried various combinations of array:flatten and array:join, but things always wind up in a sequence. (Aside: this isn't a real problem, but I'm trying to force myself to get more comfortable working with arrays and maps and this seemed like a great exercise... :) My mistake!).
E.g. map:merge(
(1 to 5) ! map {'key': array:flatten(array { . }) }, map{"duplicates":"combine"} ), (: returns map{"key":(1,2,3,4,5)} :)
map:merge( (1 to 5) ! map {'key': array:join(array {.}) }, map{"duplicates":"combine"} )
(: returns map{"key":([1],[2],[3],[4],[5])} :)
Are sequences the result because a map is a function item? Thanks for any clarity you can provide!
Best, Bridger
Am 03.08.2022 um 04:27 schrieb Bridger Dyson-Smith:
I would appreciate some help understanding how I might go about having a multi-valued array as the value of a map key, or if this is even possible; e.g.
map{ "key": [1,2,3,4,5] }
map { 'key' : array { 1 to 5 } }
Or have I missed the point?
Hi Bridger,
is even possible; e.g. map{ "key": [1,2,3,4,5] }
Well that works fine for me, so yes.
For your other examples, I think the answer is that map:merge with map{ "duplicates":"combine"} always generates value *sequences *on duplicate keys. So, maybe, generate the array you want, then put it in the map
let $a:=(1 to 5)!array{.}=>array:join() return map:entry("key",$a)
/Andy
On Wed, 3 Aug 2022 at 09:37, Martin Honnen martin.honnen@gmx.de wrote:
Am 03.08.2022 um 04:27 schrieb Bridger Dyson-Smith:
I would appreciate some help understanding how I might go about having a multi-valued array as the value of a map key, or if this is even possible; e.g.
map{ "key": [1,2,3,4,5] }
map { 'key' : array { 1 to 5 } }
Or have I missed the point?
Andy and Martin -
with apologies, I didn't express my problem very well! Martin, you're correct with your example
`map { 'key': array { 1 to 5 } }`
and that was part of my struggle; i.e. "It works this way but not that way - what am I doing wrong?" Andy noticed the source of my dilemma: I a using map:merge#2, with `map { "duplicates": "combine" }` -- Andy, thank you for catching that. I was entirely too caught up in a different part of the documentation.
I'm creating these maps from loose text, where keys are word pairs and values are value* (0, 1, or many). I'll come back with a better example of my problem, although I think you've both given me food for thought. Thank you both so much for your help! Best, Bridger
On Wed, Aug 3, 2022 at 6:04 AM Andy Bunce bunce.andy@gmail.com wrote:
Hi Bridger,
is even possible; e.g. map{ "key": [1,2,3,4,5] }
Well that works fine for me, so yes.
For your other examples, I think the answer is that map:merge with map{ "duplicates":"combine"} always generates value *sequences *on duplicate keys. So, maybe, generate the array you want, then put it in the map
let $a:=(1 to 5)!array{.}=>array:join() return map:entry("key",$a)
/Andy
On Wed, 3 Aug 2022 at 09:37, Martin Honnen martin.honnen@gmx.de wrote:
Am 03.08.2022 um 04:27 schrieb Bridger Dyson-Smith:
I would appreciate some help understanding how I might go about having a multi-valued array as the value of a map key, or if this is even possible; e.g.
map{ "key": [1,2,3,4,5] }
map { 'key' : array { 1 to 5 } }
Or have I missed the point?
basex-talk@mailman.uni-konstanz.de