Created
November 23, 2016 12:48
-
-
Save tternquist/36b4e4cc8d5e8ffc50ccc2956c47c352 to your computer and use it in GitHub Desktop.
Sum maps in XQuery (1.0-ml)
This file contains 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
xquery version "1.0-ml"; | |
declare namespace html = "http://www.w3.org/1999/xhtml"; | |
let $existing := map:entry("foo",9) | |
let $maps := ( | |
map:entry("foo",1), | |
map:entry("foo",2), | |
map:entry("foo",3), | |
map:entry("foo",4), | |
map:entry("foo",5), | |
map:entry("foo",1) | |
) | |
let $fold-join := | |
fn:fold-left( | |
function($a,$b) { | |
map:keys($b) ! map:put($a,.,(map:get($b,.),map:get($a,.))),$a | |
}, | |
?,?) | |
return | |
fn:sum($fold-join($existing,$maps)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment