Skip to content

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

@line-o

Description

@line-o

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) :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions