<div dir="auto">Hi Joe,<div dir="auto"><br></div><div dir="auto">In addition to other comments: also the size of the data matters, and not to mention the purpose of what you're trying to achieve... Small chunks are usually processed faster, so unless you just need to convert all data, perhaps limiting the set could be useful. Especially when you need yet another result, and the array would just be an intermediary result, performance may vary across implementations.</div><div dir="auto"><br></div><div dir="auto">Obviously this operation could be implemented in the host language to make it truly efficient.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Wouter</div></div><div class="gmail_extra"><br><div class="gmail_quote">Op 15 jul. 2017 21:12 schreef "Christian Grün" <<a href="mailto:christian.gruen@gmail.com">christian.gruen@gmail.com</a>>:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Joe, hi Emmanuel,<br>
<br>
Here is yet another alternative that can be efficient (but it’s not<br>
the most compact one):<br>
<br>
  let $map := map { "a": 1, "b": 2, "c": 3 }<br>
  return (<br>
    array { map:keys($map) },<br>
    array { map:for-each($map, function($key, $value) { $value }) }<br>
  )<br>
<br>
Last but not least, map:get($map, ...) can be replaced with $map(...):<br>
<br>
  let $map := map { "a": 1, "b": 2, "c": 3 }<br>
  let $keys := map:keys($map)<br>
  return (<br>
    array { $keys },<br>
    array { $keys ! $map(.) }<br>
  )<br>
<br>
Depending on the XQuery processor, and even the specific version, one<br>
or the other solution may be most efficient.<br>
<br>
Cheers,<br>
Christian<br>
<br>
<br>
<br>
On Sat, Jul 15, 2017 at 8:16 PM, Joe Wicentowski <<a href="mailto:joewiz@gmail.com">joewiz@gmail.com</a>> wrote:<br>
> Great, thank you, Emmanuel!  That is much better.<br>
><br>
> I might just offer one enhancement - switching from a FLWOR to the simple<br>
> map operator:<br>
><br>
> ```<br>
> xquery version "3.1";<br>
><br>
> let $letters-numbers := map { "a": 1, "b": 2, "c": 3 }<br>
> let $keys := map:keys($letters-numbers)<br>
> return (<br>
>     array { $keys },<br>
>     array { $keys ! map:get($letters-numbers, .) }<br>
> )<br>
> ```<br>
><br>
> Joe<br>
><br>
> On Sat, Jul 15, 2017 at 12:12 PM Emmanuel Chateau <<a href="mailto:emchateau@laposte.net">emchateau@laposte.net</a>><br>
> wrote:<br>
>><br>
>> Hi,<br>
>> I would say<br>
>><br>
>> ```<br>
>> let $letters-numbers := map { "a": 1, "b": 2, "c": 3 }<br>
>> let $keys := map:keys($letters-numbers)<br>
>> return (<br>
>>   array { $keys },<br>
>>   array { for $key in $keys return map:get($letters-numbers, $key) }<br>
>> )<br>
>> ```<br>
>> > Le 15 juil. 2017 à 11:41, Joe Wicentowski <<a href="mailto:joewiz@gmail.com">joewiz@gmail.com</a>> a écrit :<br>
>> ><br>
>> > Hi all,<br>
>> ><br>
>> > Is there an efficient way to transform entries in a map into two arrays,<br>
>> > one containing the keys and one containing the values?  Here's my attempt:<br>
>> ><br>
>> > ```<br>
>> > xquery version "3.1";<br>
>> ><br>
>> > let $letters-numbers := map { "a": 1, "b": 2, "c": 3 }<br>
>> > return<br>
>> >     (<br>
>> >         array { map:keys($letters-numbers) },<br>
>> >         array { $letters-numbers?* }<br>
>> >     )<br>
>> > ```<br>
>> ><br>
>> > This successfully takes `map { "a": 1, "b": 2, "c": 3 }` and returns<br>
>> > (["a", "b", "c"], [1, 2, 3]), but the way it iterates through the map twice<br>
>> > strikes me as somewhat inefficient.  Is there a better way to reduce this to<br>
>> > a single pass through the map, or is this actually the best approach?<br>
>> ><br>
>> > Joe<br>
>> > ______________________________<wbr>_________________<br>
>> > <a href="mailto:talk@x-query.com">talk@x-query.com</a><br>
>> > <a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank">http://x-query.com/mailman/<wbr>listinfo/talk</a><br>
>><br>
><br>
> ______________________________<wbr>_________________<br>
> <a href="mailto:talk@x-query.com">talk@x-query.com</a><br>
> <a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank">http://x-query.com/mailman/<wbr>listinfo/talk</a><br>
<br>
______________________________<wbr>_________________<br>
<a href="mailto:talk@x-query.com">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank">http://x-query.com/mailman/<wbr>listinfo/talk</a></blockquote></div></div>