Class MapMergeFunctionIterator

All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable, Serializable, RuntimeIteratorInterface

public class MapMergeFunctionIterator extends AtMostOneItemLocalRuntimeIterator
W3C XPath/XQuery map:merge:

Implements the FO 3.1 conceptual semantics:

 let $duplicates-handler := map {
   "use-first":   function($a, $b) {$a},
   "use-last":    function($a, $b) {$b},
   "combine":     function($a, $b) {$a, $b},
   "reject":      function($a, $b) {fn:error($FOJS0003)},
   "use-any":     function($a, $b) { ... implementation-dependent ... }
 },
 $combine-maps := function($A as map(*), $B as map(*), $deduplicator as function(*)) {
   fn:fold-left(map:keys($B), $A, function($z, $k){
     if (map:contains($z, $k))
     then map:put($z, $k, $deduplicator($z($k), $B($k)))
     else map:put($z, $k, $B($k))
   })
 }
 return fn:fold-left($MAPS, map{},
   $combine-maps(?, ?, $duplicates-handler(($OPTIONS?duplicates, "use-first")[1])))
 

This implementation stays local-only and mirrors that behaviour using the existing MapItem representation and MapAtomicSameKey key equality via MapItem.getSequenceByKey().

See Also: