map:put

Returns a map containing all the contents of the supplied map, but with an additional entry, which replaces any existing entry for the same key.

Signature

map:put(
    $map as map(*), 
    $key as xs:anyAtomicType, 
    $value as item()*
) as map(*)

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The function map:put returns a map that contains all entries from the supplied $map, with the exception of any entry whose key is the same key as $key, together with a new entry whose key is $key and whose associated value is $value.

The effect of the function call map:put($MAP, $KEY, $VALUE) is equivalent to the result of the following steps:

  1. let $MAP2 := map:remove($MAP, $KEY)

    This returns a map in which all entries with the same key as $KEY have been removed.

  2. Construct and return a map containing:

    1. All the entries (key/value pairs) in $MAP2, and

    2. The entry map:entry($KEY, $VALUE)

Notes

There is no requirement that the type of $key and $value be consistent with the types of any existing keys and values in the supplied map.

Examples

let $week := map{0:"Sonntag", 1:"Montag", 2:"Dienstag",
       3:"Mittwoch", 4:"Donnerstag", 5:"Freitag", 6:"Samstag"}

The expression map:put($week, 6, "Sonnabend") returns map{0:"Sonntag", 1:"Montag", 2:"Dienstag", 3:"Mittwoch", 4:"Donnerstag", 5:"Freitag", 6:"Sonnabend"}.

The expression map:put($week, -1, "Unbekannt") returns map{0:"Sonntag", 1:"Montag", 2:"Dienstag", 3:"Mittwoch", 4:"Donnerstag", 5:"Freitag", 6:"Samstag", -1:"Unbekannt"}.