-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Position of duplicates in ordered maps #1725
Comments
I think we can make this simpler if we define map:merge in terms of map:of-pairs. I think the equivalent becomes:
|
I agree: map:merge(
($default-map, { 'debug': true(), 'level': 3 }),
{ 'duplicates': use-last' }
) When it comes to reordering keys, I believe we should rather offer a separate set of functions in a later step (if we want to do so at all). Another edge case that may need to be refined in the spec is the replacement of different keys that are deemed equal ( { 1: 'integer', 2e0: 'double' }
=> map:put(1.0, 'decimal') As the stored key is changed by this update, I think we should treat it not as an in-place update, but as a delete-and-insert operation. One advantage of this would be that the resulting order would unveil what has been going on.
I think that this one should stay implementation-defined (but I have no idea how to express this in pseudo code…). |
Since we are contemplating additional options for |
…true; this has never been a mistake in the past. |
It became clear to me when writing test cases that the specs aren't entirely clear about what happens when building a map from an input sequence that contains duplicate keys. It says clearly what entry should be created for the duplicated key, but it doesn't say clearly where this entry should appear in the result.
There are four functions/instructions that this applies to: map:merge, map:build, map:of-pairs, and xsl:map.
I propose that in each case, the position of the entry for the duplicated key in the resulting map should correspond to the position of the first occurrence of that key in the input sequence. That is, "order of first appearance": the effect should be the same as if new entries are always created using a map:put() operation.
This might be slightly unexpected in the case of
map:merge()
with the optionduplicates=use-last
. It means the value will be that of the last duplicate, but its position will be that of the first duplicate. However, the other three functions/instructions achieve the effect of use-last with the callbackon-duplicates=fn{$a, $b){$a}
which only controls the value of the entry, and cannot be used to control its position, and I think it makes sense formap:merge
withduplicates=use-last
to behave in the same way.Of course we could introduce a separate option to control the position of the combined entry, but I think that would be overkill.
xsl:for-each-group
anddistinct-values
both use the "order of first appearance" rule and this has never caused any problems. (group-by
in XQuery delivers groups in implementation-dependent order, however).The text was updated successfully, but these errors were encountered: