Changes

Jump to navigation Jump to search
247 bytes added ,  14:19, 20 July 2022
no edit summary
| width='120' | '''Signatures'''
|{{Func|map:contains|$map as map(*), $key as xs:anyAtomicType|xs:boolean}}
|-valign="top"
| '''Summary'''
| Returns true if the supplied {{Code|$map}} 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.
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:entry|$key as xs:anyAtomicType, $value as item()*|map(*)}}
|-valign="top"
| '''Summary'''
| Creates a new ''map'' containing a single entry. The key of the entry in the new map is {{Code|$key}}, and its associated value is {{Code|$value}}.
Unlike the <code>map { ... }</code> expression, this technique can be used to construct a map with a variable number of entries, for example:
<syntaxhighlight lang="xquery">map:merge(for $b in //book return map:entry($b/isbn, $b))</syntaxhighlight>
|-valign="top"
| '''Examples'''
|{{Code|map:entry("M", "Monday")}} creates <code>map { "M": "Monday" }</code>.
| width='120' | '''Signatures'''
|{{Func|map:find|$input as item()*, $key as xs:anyAtomicType|array(*)}}
|-valign="top"
| '''Summary'''
| Returns all values of maps in the supplied {{Code|$input}} with the specified {{Code|$key}}. The found values will be returned in an array. Arbitrary input will be processed recursively as follows:
* In an array, all array members will be processed as sequence.
* In a map, all entries whose keys match the specified key. Moreover, all values of the map will be processed as sequence.
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:for-each|$map as map(*), $function as function(xs:anyAtomicType, item()*) as item()*|item()*}}
|-valign="top"
| '''Summary'''
|Applies the specified {{Code|$function}} to every key/value pair of the supplied {{Code|$map}} and returns the results as a sequence.
|-valign="top"
| '''Examples'''
|The following query adds the keys and values of all map entries and returns {{Code|(3,7)}}:
| width='120' | '''Signatures'''
|{{Func|map:get|$map as map(*), $key as xs:anyAtomicType|item()*}}
|-valign="top"
| '''Summary'''
|Returns the value associated with a supplied key in a given map. This function attempts to find an entry within the {{Code|$map}} 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|$map}} is a map, the expression {{Code|$map($K)}} is equivalent to {{Code|get($map, $K)}}. Similarly, the expression {{Code|get(get(get($map, 'employee'), 'name'), 'first')}} can be written as {{Code|$map('employee')('name')('first')}}.
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:keys|$map as map(*)|xs:anyAtomicType*}}
|-valign="top"
| '''Summary'''
|Returns a sequence containing all the key values present in a map. The function takes the supplied {{Code|$map}} 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.
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:merge|$maps as map(*)*|map(*)}}<br/>{{Func|map:merge|$maps as map(*)*, $options as map(*)|map(*)}}<br/>
|-valign="top"
| '''Summary'''
| Constructs and returns a new map. The ''map'' is formed by combining the contents of the supplied {{Code|$maps}}. The maps are combined as follows:
# There is one entry in the new map for each distinct key present in the union of the input maps.
# The {{Code|$options}} argument defines how duplicate keys are handled. Currently, a single option {{Code|duplicates}} exists, and its allowed values are {{Code|use-first}}, {{Code|use-last}}, {{Code|combine}} and {{Code|reject}} (default: {{Code|use-first}}).
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:put|$map as map(*), $key as xs:anyAtomicType, $value as item()*|map(*)}}
|-valign="top"
| '''Summary'''
| Creates a new ''map'', containing the entries of the supplied {{Code|$map}} and a new entry composed by {{Code|$key}} and {{Code|$value}}. The semantics of this function are equivalent to <code>map:merge((map { $key, $value }, $map))</code>
| width='120' | '''Signatures'''
|{{Func|map:remove|$map as map(*), $keys as xs:anyAtomicType*|map(*)}}<br/>
|-valign="top"
| '''Summary'''
| Constructs a new map by removing entries from an existing map. The entries in the new map correspond to the entries of {{Code|$map}}, 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.
|-valign="top"
| '''Examples'''
|
| width='120' | '''Signatures'''
|{{Func|map:size|$map as map(*)|xs:integer}}<br/>
|-valign="top"
| '''Summary'''
| Returns a the number of entries in the supplied map. The function takes the supplied {{Code|$map}} and returns the number of entries that are present in the map.
|-valign="top"
| '''Examples'''
|
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu