Joe Wicentowski
2017-07-15 15:41:22 UTC
Hi all,
Is there an efficient way to transform entries in a map into two arrays,
one containing the keys and one containing the values? Here's my attempt:
```
xquery version "3.1";
let $letters-numbers := map { "a": 1, "b": 2, "c": 3 }
return
(
array { map:keys($letters-numbers) },
array { $letters-numbers?* }
)
```
This successfully takes `map { "a": 1, "b": 2, "c": 3 }` and returns (["a",
"b", "c"], [1, 2, 3]), but the way it iterates through the map twice
strikes me as somewhat inefficient. Is there a better way to reduce this
to a single pass through the map, or is this actually the best approach?
Joe
Is there an efficient way to transform entries in a map into two arrays,
one containing the keys and one containing the values? Here's my attempt:
```
xquery version "3.1";
let $letters-numbers := map { "a": 1, "b": 2, "c": 3 }
return
(
array { map:keys($letters-numbers) },
array { $letters-numbers?* }
)
```
This successfully takes `map { "a": 1, "b": 2, "c": 3 }` and returns (["a",
"b", "c"], [1, 2, 3]), but the way it iterates through the map twice
strikes me as somewhat inefficient. Is there a better way to reduce this
to a single pass through the map, or is this actually the best approach?
Joe