-
Notifications
You must be signed in to change notification settings - Fork 15
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
array:values (resolved: map:values, map:entries) #29
Comments
It may be more useful to have
as that is more composable with things like the lookup operator, and would be more similar to how the function works in other languages. |
True, that would certainly be the better solution. The updated example: (: Query :)
let $map := map { 'a': (), 'b': 2, 'c': [ 3, 4 ] }
for $entry in map:entries($map)
return element { $entry?key } { string-join($entry?value) } |
The The main disadvantage of the first form is how to extract the key and value. (The second form enables |
The |
While there are use cases for |
Perhaps there's a case for having both |
Yes, I had similar thoughts. The simpler representation would equal the initial proposal in this issue.
I would basically regard it as functional alternative for the two-character wildcard lookup ( (//country ! map:entry(name, number(@population)))
=> map:merge()
=> map:filter(function($k, $v) { $v > 1000000 })
=> map:values() |
I'm happy with the suggested change to |
If it would return an array |
Real-life example I got per mail where Input: A movie from a movie database (simplified): Task: Get the name of all actors, a sequence of strings. He wrote: |
…map:values() from issue qt4cg#29
For I’ll keep the issue open for |
EDIT: Revised and aligned with the recently added and proposed map and array functions (#314, #357):
The suggested functions are based on the observations that:
?*
as handy shortcut;array:values
Summary
Returns all members of an array as a sequence. Equivalent to
$array?*
, but better composable and easier to read (especially for newcomers), and known from other programming languages.Signature
Example
map:values
Summary
Returns all values of a map as a sequence. Complementary to
map:keys
, and equivalent to$map?*
, but better composable and easier to read (especially for newcomers), and known from other programming languages.Signature
Example
map:entries
See #357 on composing and decomposing Key-Value Records.
Summary
Returns each entry of a map as a singleton map. Equivalent to
map:for-each($map, map:entry#2)
.Signature
Example
array:members
See #314.
The text was updated successfully, but these errors were encountered: