Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to get multiple keys from maps and arrays #8

Open
line-o opened this issue Oct 8, 2020 · 2 comments
Open

add function to get multiple keys from maps and arrays #8

line-o opened this issue Oct 8, 2020 · 2 comments

Comments

@line-o
Copy link
Owner

line-o commented Oct 8, 2020

There is a need to get a sequence of properties from a map and indexes from an array.

TODO: There might be an obvious and simpler solution to this problem

xquery version "3.1";

declare function local:map-get-sequence ($map as map(*), $keys as xs:anyAtomicType* ) as item()* {
    for-each($keys, map:get($map, ?))
};

map { 1:2, 3:4, 5:6 } => local:map-get-sequence((1, 4, 5))
(: returns  (2, 6) :)
xquery version "3.1";
declare function local:array-get-sequence ($array as array(*), $indexes as xs:integer* ) as item()* {
    for-each($indexes, array:get($array, ?))
};

[2, 4, 6] => local:array-get-sequence((1, 3))
(: returns  (2, 6) :)
@line-o
Copy link
Owner Author

line-o commented Jan 17, 2021

This does work as well:

[1,"s","s","s",5,"s","s"]
=> (function ($a, $s) { $a?($s) })((1,5))

@line-o
Copy link
Owner Author

line-o commented Mar 19, 2021

It works for all function types (array and map)

map {1: "s", "s": "s", 5:"s", "a":()}
=> (function ($array-or-map as item(), $fields as xs:anyAtomicType*) { $array-or-map?($fields) })((1, "a"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant