Changes

Jump to navigation Jump to search
6 bytes removed ,  15:50, 26 August 2014
The lookup operator provides some syntactic sugar to access values of maps or array members at a specified position. It is introduced by the question mark ({{Code|?}}) and followed by a specifier. The specifier can be:
1. a # A wildcard: {{Code|*}},2. the # The name of the key,3. an # The integer offset, or4. any # Any other parenthesized expression.
The following example demonstrates the four alternatives:
let $map := map { 'R': 'red', 'G': 'green', 'B': 'blue' }
return (
$map?* (: 1. returns all values :), $map?R (: 2. returns the value associated with the key 'R'; equivalent to $map('R') :), $map?('G','B') (: 4. returns the values associated with the key 'G' and 'B' :)
),
let $array := [ 'one', 'two', 'three' ]
return (
$array ? * (: 1. returns all values :), $array ? 1 (: 3. returns the first value; equivalent to $array(2) :), $array ? (2 to 3) (: 4. returns the value 2 and 3 :)
)
</pre>
map { 'name': 'Hildur', 'city': 'Akureyri' }
)
return $map[? name = 'Hildur'] ? city
</pre>
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu