Changes

Jump to navigation Jump to search
143 bytes removed ,  14:08, 11 October 2016
no edit summary
==map:contains==
 
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:contains|$input map as map(*), $key as xs:anyAtomicType|xs:boolean}}
|-
| '''Summary'''
| Returns true if the ''map'' supplied as {{Code|$inputmap}} contains an entry with a key equal to the supplied value of {{Code|$key}}; otherwise it returns false. No error is raised if the map contains keys that are not comparable with the supplied {{Code|$key}}.
If the supplied key is {{Code|xs:untypedAtomic}}, it is compared as an instance of {{Code|xs:string}}. If the supplied key is the {{Code|xs:float}} or {{Code|xs:double}} value {{Code|NaN}}, the function returns true if there is an entry whose key is {{Code|NaN}}, or false otherwise.
|-
==map:entry==
 
{| width='100%'
| width='120' | '''Signatures'''
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:for-each|$input map as map(*), $fun as function(xs:anyAtomicType, item()*) as item()*|item()*}}
|-
| '''Summary'''
|Applies a function to every entry of the map supplied {{Code|$inputmap}} and returns the results as a sequence. The function supplied as {{Code|$fun}} takes two arguments. It is called supplying the key of the map entry as the first argument, and the associated value as the second argument.
|-
| '''Examples'''
==map:get==
 
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:get|$input map as map(*), $key as xs:anyAtomicType|item()*}}
|-
| '''Summary'''
|Returns the value associated with a supplied key in a given map. This function attempts to find an entry within the ''map'' supplied as {{Code|$inputmap}} that has a key equal to the supplied value of {{Code|$key}}. If there is such an entry, the function returns the associated value; otherwise it returns an empty sequence. No error is raised if the map contains keys that are not comparable with the supplied {{Code|$key}}. If the supplied key is {{Code|xs:untypedAtomic}}, it is converted to {{Code|xs:string}}.
A return value of {{Code|()}} from {{Code|map:get}} could indicate that the key is present in the map with an associated value of {{Code|()}}, or it could indicate that the key is not present in the map. The two cases can be distinguished by calling {{Code|map:contains}}.
Invoking the ''map'' as a function item has the same effect as calling {{Code|get}}: that is, when {{Code|$inputmap}} is a map, the expression {{Code|$inputmap($K)}} is equivalent to {{Code|get($inputmap, $K)}}. Similarly, the expression {{Code|get(get(get($inputmap, 'employee'), 'name'), 'first')}} can be written as {{Code|$inputmap('employee')('name')('first')}}.
|-
| '''Examples'''
==map:keys==
 
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:keys|$input map as map(*)|xs:anyAtomicType*}}
|-
| '''Summary'''
|Returns a sequence containing all the key values present in a map. The function takes any ''map'' as its the supplied {{Code|$inputmap}} argument and returns the keys that are present in the map as a sequence of atomic values. The order may differ from the order in which entries were inserted in the map.
|-
| '''Examples'''
==map:merge==
 
{{Mark|Updated with Version 8.6:}} Signature extended with options argument. By default, value of first key is now adopted.
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:merge|$input maps as map(*)*|map(*)}}<br/>{{Func|map:merge|$maps as map(*)*, $options as map(*)|map(*)}}<br/>
|-
| '''Summary'''
| Constructs and returns a new map. The ''map'' is formed by combining the contents of the maps supplied in the {{Code|$inputmaps}} argument. The maps are combined as follows: # There is one entry in the new map for each distinct key value present in the union of the input maps, where .# The {{Code|$options} argument defines how duplicate keys are considered distinct according to handled. Currently, the rules of single option {{Code|duplicates}} exists, and the allowed values are {{Code|distinctuse-valuesfirst}} function.# The associated value for each such key is taken from the , {{Code|use-last map in the input sequence }}, {{Code|$inputuse-combine}} that contains an entry with this key. There is no requirement that the supplied input maps should have the same or compatible types. The type of a map (for example and {{Code|map(xs:integer, xs:string)reject}}) is descriptive of the entries it currently contains, but is not a constraint on how the map may be combined with other maps.
|-
| '''Examples'''
* {{Code|map:merge((map:entry(0, "no"), map:entry(1, "yes")))}} creates <code>map { 0: "no", 1: "yes" }</code>.
* <code>map:merge(($week, map { 7: "Unbekannt" }))</code> creates <code>map { 0: "Sonntag", 1: "Montag", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Samstag", 7: "Unbekannt" }</code>.
* <code>map:merge(($weekmap { 1:'a' }, map { 61: "Sonnabend" 'b' }), map { 'duplicates':'combine' })</code> creates <code>map { 0: "Sonntag", 1: ("Montaga", 2: "Dienstag", 3: "Mittwoch", 4: "Donnerstag", 5: "Freitag", 6: "Sonnabendb" ) }</code>.
|}
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:put|$input map as map(*), $key as xs:anyAtomicType, $value as item()*|map(*)}}
|-
| '''Summary'''
| Creates a new ''map'', containing the entries of the supplied {{Code|$inputmap}} argument and a new entry composed by {{Code|$key}} and {{Code|$value}}. The semantics of this function are equivalent to <code>map:merge(($inputmap, map { $key, $value }))</code>
|}
==map:remove==
 
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:remove|$input map as map(*), $keys as xs:anyAtomicType*|map(*)}}<br/>
|-
| '''Summary'''
| Constructs a new map by removing entries from an existing map. The entries in the new map correspond to the entries of {{Code|$inputmap}}, excluding entries supplied via {{Code|$keys}}.
No failure occurs if the input map contains no entry with the supplied keys; the input map is returned unchanged.
|-
==map:size==
 
{| width='100%'
| width='120' | '''Signatures'''
|{{Func|map:size|$input map as map(*)|xs:integer}}<br/>
|-
| '''Summary'''
| Returns a the number of entries in the supplied map. The function takes any ''map'' as its the supplied {{Code|$inputmap}} argument and returns the number of entries that are present in the map.
|-
| '''Examples'''
|}
=Changelog=
;Version 8.6=Changelog=* Updated: [[#map:merge|map:merge]] signature extended with options argument. By default, value of first key is now adopted.
;Version 8.4
;Version 8.0
 
* Added: <code>[[#map:for-each|map:for-each]]</code>, <code>[[#map:merge|map:merge]]</code>, <code>[[#map:put|map:put]]</code>
* Removed: support for collations (in accordance with the XQuery 3.1 spec).
;Version 7.8
 
* Updated: map syntax <code>map { 'key': 'value' }</code>
* Added: [[#map:serialize|map:serialize]]
;Version 7.7.1
 
* Updated: alternative map syntax without {{Code|map}} keyword and {{Code|:}} as key/value delimiter (e.g.: <code>{ 'key': 'value' })</code>
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu