Changes

Jump to navigation Jump to search
4 bytes added ,  08:46, 24 April 2011
no edit summary
A map is an additional kind of item. It comprises a collation and a set of entries. Each entry comprises a key which is an arbitrary atomic value, and an arbitrary sequence called the associated value. Within a map, no two entries have the same key, when compared using the <code>eq</code> operator under the map's collation. It is not necessary that all the keys should be mutually comparable (for example, they can include a mixture of integers and strings). Key values will never be of type <code>xs:untypedAtomic</code>, and they will never be the <code>xs:float</code> or <code>xs:double</code> value <code>NaN</code>.
The function call <code>[[#map:get|map:get($map, $key)]]</code> can be used to retrieve the value associated with a given key.
A ''map'' can also be viewed as a function from keys to associated values. To achieve this, a map is also a function item. The function corresponding to the map has the signature <code>function($key as xs:anyAtomicType) as item()*</code>. Calling the function has the same effect as calling the <code>get</code> function: the expression <code>$map($key)</code> returns the same result as <code>map:get($map, $key)</code>. For example, if <code>$books-by-isbn</code> is a map whose keys are ISBNs and whose assocated values are <code>book</code> elements, then the expression <code>$books-by-isbn("0470192747")</code> returns the <code>book</code> element with the given ISBN. The fact that a map is a function item allows it to be passed as an argument to higher-order functions that expect a function item as one of their arguments. As an example, the following query uses the higher-order function <code>fn:map($f, $seq)</code> to extract all bound values from a ''map'':
editor, reviewer
33

edits

Navigation menu