Skip to content

Instantly share code, notes, and snippets.

@emchateau
Created July 12, 2020 20:53
Show Gist options
  • Save emchateau/b1f5b5d738721c797a098a5eb84743a5 to your computer and use it in GitHub Desktop.
Save emchateau/b1f5b5d738721c797a098a5eb84743a5 to your computer and use it in GitHub Desktop.
Deep comparison of maps in XQuery
(: @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