Created
July 12, 2020 20:53
-
-
Save emchateau/b1f5b5d738721c797a098a5eb84743a5 to your computer and use it in GitHub Desktop.
Deep comparison of maps in XQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(: @see https://stackoverflow.com/questions/62844910/how-to-deep-compare-maps-to-filter-distinct-items-in-xquery :) | |
declare function local:getDistinctMaps($maps as map(*)*) as map(*)* { | |
fold-left( | |
$maps, | |
(), | |
function($distinct-maps, $new-map) { | |
if (some $map in $distinct-maps satisfies deep-equal($map, $new-map)) | |
then $distinct-maps else ($distinct-maps, $new-map) | |
} | |
) | |
}; | |
let $map1 := map{ | |
'a' : '1', | |
'b' : '2' | |
} | |
let $map2 := map{ | |
'c' : '3', | |
'd' : '4' | |
} | |
let $map3 := map{ | |
'a' : '1', | |
'b' : '2' | |
} | |
return local:getDistinctMaps( ($map1, $map2, $map3) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment