Skip to content

Instantly share code, notes, and snippets.

@tternquist
Created November 23, 2016 12:48
Show Gist options
  • Save tternquist/36b4e4cc8d5e8ffc50ccc2956c47c352 to your computer and use it in GitHub Desktop.
Save tternquist/36b4e4cc8d5e8ffc50ccc2956c47c352 to your computer and use it in GitHub Desktop.
Sum maps in XQuery (1.0-ml)
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