Changes

Jump to navigation Jump to search
311 bytes added ,  20:42, 9 August 2014
no edit summary
==Maps==
A ''map '' is an additional kind of item. It comprises a collation and function that associates a set of entrieskeys with values, resulting in a collection of key/value pairs. Each key/value pair in a map is called an entry comprises a . A key which is an arbitrary atomic value, and the associated value is an arbitrary sequence called the associated value. Within a map, no two entries have the same key, when compared using the {{Code|eq}} 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}}, and they will never be the {{Code|xs:float}} or {{Code|xs:double}} value {{Code|NaN}}.
The function call <code>[[Map Module#map:get|map:get($map, $key)]]</code> can be used to retrieve the value associated with a given key. A ''map'' can 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()*}}. Calling the function has the same effect as calling the {{Code|get}} function: the The expression {{Code|$map($key)}} returns the same result as associated value; the function call {{Code|map:get($map, $key)}}is equivalent. For example, if {{Code|$books-by-isbn}} is a map whose keys are ISBNs and whose associated values are {{Code|book}} elements, then the expression {{Code|$books-by-isbn("0470192747")}} returns the {{Code|book}} 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)}} to extract all bound values from a ''map'':
<pre class="brush:xquery">
Because a map is a function item, functions that apply to functions also apply to maps. A map is an anonymous function, so {{Code|fn:function-name}} returns the empty sequence; {{Code|fn:function-arity}} always returns {{Code|1}}.
Maps may be compared using the {{Code|fn:deep-equal}} function. The semantics for this [[Map Module]] describes the available set of map functions. ==Arrays== An ''array'' is a function are extended so that when two items are comparedassociates a set of positions, at any level of recursionrepresented as positive integer keys, with values. The first position in an array is associated with the items compare equal if they integer {{Code|1}}. The values of an array are both mapscalled its members. In the type hierarchy, if both use the same collationarray has a distinct type, if both contain which is derived from function.  The function corresponding to the same set of keys (compared using array has the signature {{Code|eqfunction($index as xs:integer) as item()*}} operator. The expression {{Code|$array($index), without regard }} returns the associated member. The fact that an array is a function item allows it to be passed as an argument to orderinghigher-order functions that expect a function item as one of their arguments. Like all other values, and if for each key that is present in both mapsarrays are immutable. For example, the associated values are deep<code>[[Array Module#array:reverse|array:reverse]]</code> function creates a new array containing a re-equal. When comparing mapsordering of the members of an existing array, but the maps' collation existing array is used rather than not changed by the collation supplied as an argument operation. Like sequences, arrays have no identity. It is meaningful to compare the {{Code|fncontents of two arrays, but there is no way of asking whether they are "the same array":deep-equal}} functiontwo arrays with the same content are indistinguishable.
Arrays may be compared using the {{Code|fn:deep-equal}} function. The [[Map Array Module]] describes all map the available set of array functions.
==Functions==
XQuery 3.1 is still subject to change, but the following features and functions will be added soon:
* Support for arrays: data structure, functions
* Arrow operator (<code>=></code>): applies a function to an item, using the item as the first argument to the function. The expression <code>$i=>$f()</code> is equivalent to <code>$f($i)</code>, and <code>$i=>$f($j)</code> is equivalent to <code>$f($i, $j)</code>.
* Map lookup operator (<code>?</code>): returns the value of a map for a specific key. The expression <code>$map('name')</code> is equivalent to <code>$map?name</code>.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu